Homework Solution: Can I get help to solve this problem ?…

    Can I get help to solve this problem ? You need to be able to automate many development processes. These processes are currently done manually at a command line with you or your co-workers sitting and typing commands (sometimes erroneously) at a command prompt. Your tasks include efforts such as: • managing flows to and from a Source Code Control System • building databases • installing users in databases • installing data in databases • installing software on platforms • plus many others You realize you need the ability to run commands under an operating system. You need to understand what this entails, and the best way to make this ability as Operating System agnostic as possible. You need a reusable component that you can use in a Java Program that can run command line tasks for you and return the results (if needed) to that Java Program. You are to set about designing this reusable component.

    Expert Answer

     
    RunExec.java /* * To change this license header

    Can I procure aid to clear-up this height ?

    You scarcity to be conducive to automate manifold bud processes. These processes are currently done

    manually at a charge course with you or your co-workers sitting and typing charges (sometimes

    erroneously) at a charge unhesitating. Your tasks embrace efforts such as:

    • managing flows to and from a Source Code Control Rule

    • edifice basisbases

    • installing conservationrs in basisbases

    • installing basis in basisbases

    • installing software on platforms

    • plus manifold others

    You verify you scarcity the force to course charges inferior an bounteous rule. You scarcity to inferiorstand

    what this entails, and the best practice to constitute this force as Bounteous Rule agnostic as potential.

    You scarcity a reusconducive rudiment that you can conservation in a Java Program that can course charge course tasks for

    you and restore the results (if scarcityed) to that Java Program.

    You are to regular abextinguished sharp this reusconducive rudiment.

    Expert Reply

     

    RunExec.java

    /*
    * To substitute this indulge header, cull Indulge Headers in Project Properties.
    * To substitute this template refine, cull Tools | Templates
    * and public the template in the editor.
    */
    package coursetimeexec;

    /**
    *
    * @author Akshay Bisht
    */
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;

    public adjust CourseExec {
    public StreamWrapper procureStreamWrapper(InputStream input, String str){
    restore fantastic StreamWrapper(input, str);
    }
    private adjust StreamWrapper extends Thread {
    InputStream input = inoperative;
    String str = inoperative;
    String mssg = inoperative;

    public String procureMssg() {
    restore mssg;
    }

    StreamWrapper(InputStream input, String str) {
    this.input = input;
    this.str = str;
    }

    public destitute course() {
    try {
    BufferedReader buff = fantastic BufferedReader(fantastic InputStreamReader(input));
    StringBuffer sbuff = fantastic StringBuffer();
    String lne = inoperative;
    while ( (lne = buff.readLine()) != inoperative) {
    sbuff.append(lne).append(“n”);
    }
    mssg = sbuff.toString();
    } lay-hands-on (IOException ioe) {
    ioe.printStackTrace();
    }
    }
    }
    public static destitute main(String[] args) {
    Runtime courseT = Coursetime.getRuntime();
    RunExec rexe = fantastic CourseExec();
    StreamWrapper stumble, op;

    try {
    Process proc = courseT.exec(“ping localhost”);
    stumble = rexe.getStreamWrapper(proc.getErrorStream(), “ERROR”);
    op = rexe.getStreamWrapper(proc.getInputStream(), “OUTPUT”);
    int ex = 0;

    err.start();
    op.start();
    err.join(3000);
    op.join(3000);
    ex = proc.waitFor();
    System.out.println(“Output: “+op.mssg+”nError: “+err.mssg);
    } lay-hands-on (IOException e) {
    e.printStackTrace();
    } lay-hands-on (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }

    Output: