Package javaforce

Class ShellProcess

java.lang.Object
javaforce.ShellProcess

public class ShellProcess extends Object
  • Field Details

    • log

      public static boolean log
    • logPrompt

      public static boolean logPrompt
    • command

      public String command
  • Constructor Details

    • ShellProcess

      public ShellProcess()
  • Method Details

    • addResponse

      public void addResponse(String prompt, String reply, boolean repeat)
      Registers a response to a prompt. If repeat is true the response can be used many times.
    • addTerminate

      public void addTerminate(String prompt)
      Terminates the program if prompt is detected.
    • addRegexResponse

      public void addRegexResponse(String prompt_regex, String reply, boolean repeat)
      Registers a response to a prompt in the form of a regex. If repeat is true the response can be used many times.
    • addRegexTerminate

      public void addRegexTerminate(String prompt_regex)
      Terminates the program if prompt_regex is detected.
    • addListener

      public void addListener(ShellProcessListener listener)
      The listener will receive all output.
    • getListener

      public ShellProcessListener getListener()
    • addEnvironmentVariable

      public void addEnvironmentVariable(String name, String value)
    • removeEnvironmentVariable

      public void removeEnvironmentVariable(String name)
    • setFolder

      public void setFolder(File path)
      Sets init working folder.
    • keepOutput

      public void keepOutput(boolean state)
      Keep all output (default). Note that responses are disabled when this is disabled. Disabling this is intended for long processes that are monitored with a ShellProcessListener
    • run

      public String run(List<String> cmd, boolean redirStderr)
      See run(String cmd[], boolean redirStderr)
    • run

      public String run(String[] cmd, boolean redirStderr)
      Runs a process, sending responses to stdin and returning all stdout. The responses should cause the process to terminate. If cmd[0] is 'sudo' then jfsudo-ask is used if a password is required to run the command. If redirStderr is true then stderr will be redir to stdout.
    • destroy

      public void destroy()
      Terminates the process.
    • destroyForcibly

      public void destroyForcibly()
      Forcibly Terminates the process.
    • getStdout

      public String getStdout()
    • getStderr

      public String getStderr()
    • getOutput

      public ShellProcess.Output getOutput()
    • getErrorLevel

      public int getErrorLevel()
      Returns error level from last process run.
    • getOutputStream

      public OutputStream getOutputStream()
    • isAlive

      public boolean isAlive()
    • getProcess

      public Process getProcess()
    • exec

      public static ShellProcess.Output exec(String[] cmd, boolean redirStderr)
      Executes a command and returns the ShellProcess.Output with stdout, stderr and errorLevel.
    • exec

      public static ShellProcess.Output exec(String[] cmd)
      Executes a command and returns the ShellProcess.Output with stdout, stderr and errorLevel. stderr is NOT redirected to stdout.