Class ShellExec

java.lang.Object
org.photonvision.common.util.ShellExec

public class ShellExec extends Object
Execute external process and optionally read output buffer.
  • Constructor Details

    • ShellExec

      public ShellExec()
    • ShellExec

      public ShellExec(boolean readOutput, boolean readError)
  • Method Details

    • executeBashCommand

      public int executeBashCommand(String command) throws IOException
      Throws:
      IOException
    • executeBashCommand

      public int executeBashCommand(String command, boolean wait) throws IOException
      Execute a bash command. We can handle complex bash commands including multiple executions (; | and ||), quotes, expansions ($), escapes (\), e.g.: "cd /abc/def; mv ghi 'older ghi '$(whoami)"
      Parameters:
      command - Bash command to execute
      Returns:
      true if bash got started, but your command may have failed.
      Throws:
      IOException
    • execute

      public int execute(String command, String... args) throws IOException
      Execute a command in current folder, and wait for process to end
      Parameters:
      command - command ("c:/some/folder/script.bat" or "some/folder/script.sh")
      args - 0..n command line arguments
      Returns:
      process exit code
      Throws:
      IOException
    • execute

      public int execute(String command, String workdir, boolean wait, String... args) throws IOException
      Execute a command.
      Parameters:
      command - command ("c:/some/folder/script.bat" or "some/folder/script.sh")
      workdir - working directory or NULL to use command folder
      wait - wait for process to end
      args - 0..n command line arguments
      Returns:
      process exit code
      Throws:
      IOException
    • getExitCode

      public int getExitCode()
    • isOutputCompleted

      public boolean isOutputCompleted()
    • isErrorCompleted

      public boolean isErrorCompleted()
    • getOutput

      public String getOutput()
    • getError

      public String getError()