Class CLIExec
java.lang.Object
uk.theretiredprogrammer.actionssupport.CLIExec
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Execute the CLI command as a process.voidExecute the CLI command as a process.Define the tab to be used, if the Output Window is to be used for input or output.Add a cancel icon in the Output Window Toolbar.postprocessing(Consumer<org.openide.windows.OutputWriter> postprocessing) Define a method to be executed after to the main Execute Process running.preprocessing(Consumer<org.openide.windows.OutputWriter> preprocessing) Define a method to be executed prior to the main Execute Process running.voidprinterror(String phase, String exmsg) Attempt to write an error message to the STDERR receiver.A File accepts STDERR output.stderr(OutputStream os) An OutputStream accepts STDERR output.A Writer accepts STDERR output.stderr(org.openide.filesystems.FileObject fo) A FileObject accepts STDERR output.Present both STDOUT and STDERR outputs on STDOUT.Present STDERR in the Output Window.A File is the STDIN source.stdin(InputStream is) An InputStream is the STDIN source.A Reader is the STDIN source.stdin(org.openide.filesystems.FileObject fo) A FileObject is the STDIN source.Use the default period of inactivity prior to flushing the STDIN stream.stdinFlushPeriod(int millisecs) Define the period of inactivity prior to flushing the STDIN stream.The Output Window is the STDIN source.A File accepts STDOUT output.stdout(OutputStream os) An OutputStream accepts STDOUT output.A Writer accepts STDOUT output.stdout(org.openide.filesystems.FileObject fo) A FileObject accepts STDOUT output.Present STDOUT in the Output Window.
-
Constructor Details
-
CLIExec
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
A FileObject accepts STDOUT output.- Parameters:
fo- The FileObject that accepts data from the Processes STDOUT stream.- Returns:
- this object
-
stdout
A File accepts STDOUT output.- Parameters:
file- The File that accepts data from the Processes STDOUT stream.- Returns:
- this object
-
stdout
An OutputStream accepts STDOUT output.- Parameters:
os- The OutputStream that accepts data from the Processes STDOUT stream.- Returns:
- this object
-
stdout
A Writer accepts STDOUT output.- Parameters:
wtr- The writer that accepts data from the Processes STDOUT stream.- Returns:
- this object
-
stdoutToOutputWindow
Present STDOUT in the Output Window.- Returns:
- this object
-
stderr
A FileObject accepts STDERR output.- Parameters:
fo- The FileObject that accepts data from the Processes STDERR stream.- Returns:
- this object
-
stderr
A File accepts STDERR output.- Parameters:
file- The File that accepts data from the Processes STDERR stream.- Returns:
- this object
-
stderr
An OutputStream accepts STDERR output.- Parameters:
os- The OutputStream that accepts data from the Processes STDERR stream.- Returns:
- this object
-
stderr
A Writer accepts STDERR output.- Parameters:
wtr- The Writer that accepts data from the Processes STDERR stream.- Returns:
- this object
-
stderrToOutputWindow
Present STDERR in the Output Window.- Returns:
- this object
-
stderr2stdoutput
Present both STDOUT and STDERR outputs on STDOUT.- Returns:
- this object
-
stdin
A FileObject is the STDIN source.- Parameters:
fo- The FileObject that provides data for the Processes STDIN stream.- Returns:
- this object
-
stdin
A File is the STDIN source.- Parameters:
file- The File that provides data for the Processes STDIN stream.- Returns:
- this object
-
stdin
An InputStream is the STDIN source.- Parameters:
is- The InputStream that provides data for the Processes STDIN stream.- Returns:
- this object
-
stdin
A Reader is the STDIN source.- Parameters:
rdr- The Reader that provides data for the Processes STDIN stream.- Returns:
- this object
-
stdinFromOutputWindow
The Output Window is the STDIN source.- Returns:
- this object
-
stdinFlushPeriod
Define the period of inactivity prior to flushing the STDIN stream.- Parameters:
millisecs- a milliseconds period- Returns:
- this object
-
stdinFlushPeriod
Use the default period of inactivity prior to flushing the STDIN stream.- Returns:
- this object
-
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
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
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
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
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
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 phaseexmsg- the exception message
-