java.lang.Object
uk.theretiredprogrammer.actionssupport.CLIExec

public class CLIExec extends Object
CLIExec implements both configuration prior to execution of a CLI style command and also its execution. Builder style method chaining is provided for configuration includes both general configuration and input/output options. Execution methods are available to utilise either an Output Window tab, in addition to a basic execution option. Details of the CLI Command String, which includes limited parameter substitution where ${NODEPATH} is replaced with the node folder path. The command has to be parsed into CLI "phrases", such as options, option parameters, filenames etc. As this constructor never can have a full understanding of every command's syntax, it employs a basic parsing technique (breaking on word breaks i.e. white space). This works in the vast majority of cases, but there are times where the CLI "phrase" should include multiple words. If this is the case, the phrase should be written with enclosing double quotes. These quotes will be stripped from the generated command prior to it being passed to ProcessBuilder.
  • Constructor Details

    • CLIExec

      public CLIExec(org.openide.filesystems.FileObject dir, String clicommand)
      Create the initial CLIExec object with the mandatory information. The initial state for IO is: STDIN - no data passed to stream, STDOUT - discarded, STDERR - discarded, STDIN flush period = 0 (ie OFF). It can be configured by use of the various builder style methods.
      Parameters:
      dir - The node folder - will be used as the working directory when executing this object.
      clicommand - the command to be run when executing this command.
  • Method Details

    • stdout

      public CLIExec stdout(org.openide.filesystems.FileObject fo)
      A FileObject accepts STDOUT output.
      Parameters:
      fo - The FileObject that accepts data from the Processes STDOUT stream.
      Returns:
      this object
    • stdout

      public CLIExec stdout(File file)
      A File accepts STDOUT output.
      Parameters:
      file - The File that accepts data from the Processes STDOUT stream.
      Returns:
      this object
    • stdout

      public CLIExec stdout(OutputStream os)
      An OutputStream accepts STDOUT output.
      Parameters:
      os - The OutputStream that accepts data from the Processes STDOUT stream.
      Returns:
      this object
    • stdout

      public CLIExec stdout(Writer wtr)
      A Writer accepts STDOUT output.
      Parameters:
      wtr - The writer that accepts data from the Processes STDOUT stream.
      Returns:
      this object
    • stdoutToOutputWindow

      public CLIExec stdoutToOutputWindow()
      Present STDOUT in the Output Window.
      Returns:
      this object
    • stderr

      public CLIExec stderr(org.openide.filesystems.FileObject fo)
      A FileObject accepts STDERR output.
      Parameters:
      fo - The FileObject that accepts data from the Processes STDERR stream.
      Returns:
      this object
    • stderr

      public CLIExec stderr(File file)
      A File accepts STDERR output.
      Parameters:
      file - The File that accepts data from the Processes STDERR stream.
      Returns:
      this object
    • stderr

      public CLIExec stderr(OutputStream os)
      An OutputStream accepts STDERR output.
      Parameters:
      os - The OutputStream that accepts data from the Processes STDERR stream.
      Returns:
      this object
    • stderr

      public CLIExec stderr(Writer wtr)
      A Writer accepts STDERR output.
      Parameters:
      wtr - The Writer that accepts data from the Processes STDERR stream.
      Returns:
      this object
    • stderrToOutputWindow

      public CLIExec stderrToOutputWindow()
      Present STDERR in the Output Window.
      Returns:
      this object
    • stderr2stdoutput

      public CLIExec stderr2stdoutput()
      Present both STDOUT and STDERR outputs on STDOUT.
      Returns:
      this object
    • stdin

      public CLIExec stdin(org.openide.filesystems.FileObject fo)
      A FileObject is the STDIN source.
      Parameters:
      fo - The FileObject that provides data for the Processes STDIN stream.
      Returns:
      this object
    • stdin

      public CLIExec stdin(File file)
      A File is the STDIN source.
      Parameters:
      file - The File that provides data for the Processes STDIN stream.
      Returns:
      this object
    • stdin

      public CLIExec stdin(InputStream is)
      An InputStream is the STDIN source.
      Parameters:
      is - The InputStream that provides data for the Processes STDIN stream.
      Returns:
      this object
    • stdin

      public CLIExec stdin(Reader rdr)
      A Reader is the STDIN source.
      Parameters:
      rdr - The Reader that provides data for the Processes STDIN stream.
      Returns:
      this object
    • stdinFromOutputWindow

      public CLIExec stdinFromOutputWindow()
      The Output Window is the STDIN source.
      Returns:
      this object
    • stdinFlushPeriod

      public CLIExec stdinFlushPeriod(int millisecs)
      Define the period of inactivity prior to flushing the STDIN stream.
      Parameters:
      millisecs - a milliseconds period
      Returns:
      this object
    • stdinFlushPeriod

      public CLIExec stdinFlushPeriod()
      Use the default period of inactivity prior to flushing the STDIN stream.
      Returns:
      this object
    • preprocessing

      public CLIExec preprocessing(Consumer<org.openide.windows.OutputWriter> preprocessing)
      Define a method to be executed prior to the main Execute Process running. This method will be executed as part of the Execute method, if the OutputWindow is to be used for input or output.
      Parameters:
      preprocessing - the pre processing method
      Returns:
      this object
    • postprocessing

      public CLIExec postprocessing(Consumer<org.openide.windows.OutputWriter> postprocessing)
      Define a method to be executed after to the main Execute Process running. This method will be executed as part of the Execute method, if the OutputWindow is to be used for input or output.
      Parameters:
      postprocessing - the post processing method
      Returns:
      this object
    • ioTabName

      public CLIExec ioTabName(String tabname)
      Define the tab to be used, if the Output Window is to be used for input or output.
      Parameters:
      tabname - that output window tabname to be used.
      Returns:
      this object
    • needsCancel

      public CLIExec needsCancel()
      Add a cancel icon in the Output Window Toolbar. It's action will be to cancel the Process generated by the execute command.
      Returns:
      this object
    • execute

      public void execute(String startmessage)
      Execute the CLI command as a process. The execution process will be connected to the defined STDIN, STDOUT and STDERR data and execution started in its own Process. This method will wait for the process to complete before returning. If an Output Window is being used, then the startmessage will be written to the window prior to executing the command and the message "... doneE will be written to the window once execution is completed.
      Parameters:
      startmessage - the start message to be written to the Output window.
    • execute

      public void execute()
      Execute the CLI command as a process. The execution process will be connected to the defined STDIN, STDOUT and STDERR data and execution started in its own Process. This method will wait for the process to complete before returning.
    • printerror

      public void printerror(String phase, String exmsg)
      Attempt to write an error message to the STDERR receiver. The error message will combine the Phase parameter and the Exception Message parameter. If there is a defined STDERR receiver then the error message will be written to that stream/writer/file. If the STDERR receiver has not been defined then the error message will be written to the Status Display.
      Parameters:
      phase - the phase
      exmsg - the exception message