Class CommandLineUtils


  • public abstract class CommandLineUtils
    extends java.lang.Object
    • Field Detail

      • MILLIS_PER_SECOND

        private static final long MILLIS_PER_SECOND
        Number of milliseconds per second.
        See Also:
        Constant Field Values
      • NANOS_PER_SECOND

        private static final long NANOS_PER_SECOND
        Number of nanoseconds per second.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CommandLineUtils

        public CommandLineUtils()
    • Method Detail

      • executeCommandLine

        public static int executeCommandLine​(Commandline cl,
                                             java.io.InputStream systemIn,
                                             StreamConsumer systemOut,
                                             StreamConsumer systemErr,
                                             int timeoutInSeconds)
                                      throws CommandLineException
        Parameters:
        cl - The command line to execute
        systemIn - The input to read from, must be thread safe
        systemOut - A consumer that receives output, must be thread safe
        systemErr - A consumer that receives system error stream output, must be thread safe
        timeoutInSeconds - Positive integer to specify timeout, zero and negative integers for no timeout.
        Returns:
        A return value, see Process.exitValue()
        Throws:
        CommandLineException - or CommandLineTimeOutException if time out occurs
      • executeCommandLineAsCallable

        public static CommandLineCallable executeCommandLineAsCallable​(Commandline cl,
                                                                       java.io.InputStream systemIn,
                                                                       StreamConsumer systemOut,
                                                                       StreamConsumer systemErr,
                                                                       int timeoutInSeconds)
                                                                throws CommandLineException
        Immediately forks a process, returns a callable that will block until process is complete.
        Parameters:
        cl - The command line to execute
        systemIn - The input to read from, must be thread safe
        systemOut - A consumer that receives output, must be thread safe
        systemErr - A consumer that receives system error stream output, must be thread safe
        timeoutInSeconds - Positive integer to specify timeout, zero and negative integers for no timeout.
        Returns:
        A CommandLineCallable that provides the process return value, see Process.exitValue(). "call" must be called on this to be sure the forked process has terminated, no guarantees is made about any internal state before after the completion of the call statements
        Throws:
        CommandLineException - or CommandLineTimeOutException if time out occurs
      • getSystemEnvVars

        public static java.util.Properties getSystemEnvVars()
        Gets the shell environment variables for this process. Note that the returned mapping from variable names to values will always be case-sensitive regardless of the platform, i.e. getSystemEnvVars().get("path") and getSystemEnvVars().get("PATH") will in general return different values. However, on platforms with case-insensitive environment variables like Windows, all variable names will be normalized to upper case.
        Returns:
        The shell environment variables, can be empty but never null.
        See Also:
        System.getenv() API, new in JDK 5.0, to get the same result since 2.0.2 System#getenv() will be used if available in the current running jvm.
      • getSystemEnvVars

        public static java.util.Properties getSystemEnvVars​(boolean caseSensitive)
        Return the shell environment variables. If caseSensitive == true, then envar keys will all be upper-case.
        Parameters:
        caseSensitive - Whether environment variable keys should be treated case-sensitively.
        Returns:
        Properties object of (possibly modified) envar keys mapped to their values.
        See Also:
        System.getenv() API, new in JDK 5.0, to get the same result since 2.0.2 System#getenv() will be used if available in the current running jvm.
      • isAlive

        public static boolean isAlive​(java.lang.Process p)
      • translateCommandline

        public static java.lang.String[] translateCommandline​(java.lang.String toProcess)
                                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • toString

        public static java.lang.String toString​(java.lang.String[] line)