Class Command

  • All Implemented Interfaces:
    AdditionalInformationHandler, ClassCrossReference, CleanUpHandler, CrossReference, Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, EnvironmentVariablesHandler, WorkingDirectoryHandler, OptionHandler, QuickInfoSupporter, ShallowCopySupporter<Actor>, SizeOfHandler, Stoppable, StoppableWithFeedback, VariablesInspectionHandler, VariableChangeListener, Actor, ErrorHandler, OutputProducer, com.github.fracpete.processoutput4j.core.StreamingProcessOwner, Serializable, Comparable

    public class Command
    extends AbstractSource
    implements ClassCrossReference, com.github.fracpete.processoutput4j.core.StreamingProcessOwner, EnvironmentVariablesHandler, WorkingDirectoryHandler
    Runs an external system command and broadcasts the generated output (stdout and/or stderr) continuously, opposed to adams.flow.source.Exec which waits for the command to finish.

    See also:
    adams.flow.source.Exec

    Input/output:
    - generates:
       java.lang.String


    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: Command
     
    -annotation <adams.core.base.BaseAnnotation> (property: annotations)
        The annotations to attach to this actor.
        default:
     
    -skip <boolean> (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded
        as it is.
        default: false
     
    -stop-flow-on-error <boolean> (property: stopFlowOnError)
        If set to true, the flow execution at this level gets stopped in case this
        actor encounters an error; the error gets propagated; useful for critical
        actors.
        default: false
     
    -silent <boolean> (property: silent)
        If enabled, then no errors are output in the console; Note: the enclosing
        actor handler must have this enabled as well.
        default: false
     
    -cmd <adams.core.base.BaseText> (property: command)
        The external command to run.
        default: ls -l .
     
    -working-directory <java.lang.String> (property: workingDirectory)
        The current working directory for the command.
        default:
     
    -env-var <adams.core.base.BaseKeyValuePair> [-env-var ...] (property: envVars)
        The environment variables to overlay on top of the current ones.
        default:
     
    -placeholder <boolean> (property: commandContainsPlaceholder)
        Set this to true to enable automatic placeholder expansion for the command
        string.
        default: false
     
    -variable <boolean> (property: commandContainsVariable)
        Set this to true to enable automatic variable expansion for the command
        string.
        default: false
     
    -output-type <STDOUT|STDERR|BOTH> (property: outputType)
        Determines the output type; if BOTH is selected then an array is output
        with stdout as first element and stderr as second
        default: STDOUT
     
    -prefix-stdout <java.lang.String> (property: prefixStdOut)
        The (optional) prefix to use for output from stdout.
        default:
     
    -prefix-stderr <java.lang.String> (property: prefixStdErr)
        The (optional) prefix to use for output from stderr.
        default:
     
    -time-out <int> (property: timeOut)
        The maximum time in seconds for the process to run before getting killed,
         ignored if less than 1.
        default: -1
        minimum: -1
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_Command

        protected BaseText m_Command
        the command to run.
      • m_WorkingDirectory

        protected String m_WorkingDirectory
        the current working directory.
      • m_CommandContainsPlaceholder

        protected boolean m_CommandContainsPlaceholder
        whether the replace string contains a placeholder, which needs to be expanded first.
      • m_CommandContainsVariable

        protected boolean m_CommandContainsVariable
        whether the replace string contains a variable, which needs to be expanded first.
      • m_OutputType

        protected com.github.fracpete.processoutput4j.core.StreamingProcessOutputType m_OutputType
        whether to output stderr instead of stdout or both.
      • m_PrefixStdOut

        protected String m_PrefixStdOut
        the stdout prefix.
      • m_PrefixStdErr

        protected String m_PrefixStdErr
        the stderr prefix.
      • m_Output

        protected List m_Output
        the tokens to forward.
      • m_ProcessOutput

        protected transient com.github.fracpete.processoutput4j.output.StreamingProcessOutput m_ProcessOutput
        the process monitor.
      • m_ExecutionFailure

        protected IllegalStateException m_ExecutionFailure
        in case an exception occurred executing the command (gets rethrown).
      • m_TimeOut

        protected int m_TimeOut
        the time out in seconds.
    • Constructor Detail

      • Command

        public Command()
    • Method Detail

      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class AbstractActor
      • setCommand

        public void setCommand​(BaseText value)
        Sets the command to run.
        Parameters:
        value - the command
      • getCommand

        public BaseText getCommand()
        Returns the command to run.
        Returns:
        the command
      • commandTipText

        public String commandTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setWorkingDirectory

        public void setWorkingDirectory​(String value)
        Sets the current working directory for the command.
        Specified by:
        setWorkingDirectory in interface WorkingDirectoryHandler
        Parameters:
        value - the directory, ignored if empty
      • workingDirectoryTipText

        public String workingDirectoryTipText()
        Returns the tip text for this property.
        Specified by:
        workingDirectoryTipText in interface WorkingDirectoryHandler
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • envVarsTipText

        public String envVarsTipText()
        Returns the tip text for this property.
        Specified by:
        envVarsTipText in interface EnvironmentVariablesHandler
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setCommandContainsPlaceholder

        public void setCommandContainsPlaceholder​(boolean value)
        Sets whether the command string contains a placeholder which needs to be expanded first.
        Parameters:
        value - true if command string contains a placeholder
      • getCommandContainsPlaceholder

        public boolean getCommandContainsPlaceholder()
        Returns whether the command string contains a placeholder which needs to be expanded first.
        Returns:
        true if command string contains a placeholder
      • commandContainsPlaceholderTipText

        public String commandContainsPlaceholderTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setCommandContainsVariable

        public void setCommandContainsVariable​(boolean value)
        Sets whether the command string contains a variable which needs to be expanded first.
        Parameters:
        value - true if command string contains a variable
      • getCommandContainsVariable

        public boolean getCommandContainsVariable()
        Returns whether the command string contains a variable which needs to be expanded first.
        Returns:
        true if command string contains a variable
      • commandContainsVariableTipText

        public String commandContainsVariableTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setOutputType

        public void setOutputType​(com.github.fracpete.processoutput4j.core.StreamingProcessOutputType value)
        Sets what output from the process to forward.
        Parameters:
        value - the output type
      • getOutputType

        public com.github.fracpete.processoutput4j.core.StreamingProcessOutputType getOutputType()
        Returns what output from the process to forward.
        Specified by:
        getOutputType in interface com.github.fracpete.processoutput4j.core.StreamingProcessOwner
        Returns:
        the output type
      • outputTypeTipText

        public String outputTypeTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPrefixStdOut

        public void setPrefixStdOut​(String value)
        Sets the (optional) prefix to use for output from stdout.
        Parameters:
        value - the prefix
      • getPrefixStdOut

        public String getPrefixStdOut()
        Returns the (optional) prefix to use for output from stdout.
        Returns:
        the prefix
      • prefixStdOutTipText

        public String prefixStdOutTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setPrefixStdErr

        public void setPrefixStdErr​(String value)
        Sets the (optional) prefix to use for output from stderr.
        Parameters:
        value - the prefix
      • getPrefixStdErr

        public String getPrefixStdErr()
        Returns the (optional) prefix to use for output from stderr.
        Returns:
        the prefix
      • prefixStdErrTipText

        public String prefixStdErrTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTimeOut

        public void setTimeOut​(int value)
        Sets the time out for the process.
        Parameters:
        value - the time out in seconds
      • getTimeOut

        public int getTimeOut()
        Returns the time out for the process.
        Returns:
        the time out in seconds
      • timeOutTipText

        public String timeOutTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • generates

        public Class[] generates()
        Returns the class of objects that it generates.
        Specified by:
        generates in interface OutputProducer
        Returns:
        java.lang.String.class
      • doExecute

        protected String doExecute()
        Executes the flow item.
        Specified by:
        doExecute in class AbstractActor
        Returns:
        null if everything is fine, otherwise error message
      • processOutput

        public void processOutput​(String line,
                                  boolean stdout)
        Adds the line from the output to the internal list of lines to output.
        Specified by:
        processOutput in interface com.github.fracpete.processoutput4j.core.StreamingProcessOwner
        Parameters:
        line - the line to add
        stdout - whether stdout or stderr
      • output

        public Token output()
        Returns the generated token.
        Specified by:
        output in interface OutputProducer
        Returns:
        the generated token
      • hasPendingOutput

        public boolean hasPendingOutput()
        Checks whether there is pending output to be collected after executing the flow item.
        Specified by:
        hasPendingOutput in interface OutputProducer
        Returns:
        true if there is pending output