Package gw.util

Class ProcessStarter

    • Constructor Detail

      • ProcessStarter

        public ProcessStarter​(String command)
        Deprecated.
    • Method Detail

      • exec

        public String exec()
        Deprecated.

        Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and returns all content sent to standard out as a string. If the command finishes with a non zero return value, a CommandFailedException is thrown.

        Content sent to standard error by the command will be forwarded to standard error for this JVM.

        This method blocks on the execution of the command.

        Example Usages:

           var currentDir = Shell.exec( "dir" ) // windows
           var currentDir = Shell.exec( "ls" )  // *nix
           Shell.exec( "rm -rf " + directoryToNuke )
         

        Returns:
        the content of standard out
        Throws:
        CommandFailedException - if the process finishes with a non-zero return value
      • execWithPipe

        public void execWithPipe()
        Deprecated.

        Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and pipes all data sent to this processes stdout, stderr, and stdin. If the command finishes with a non zero return value, a CommandFailedException is thrown.

        Stdout and Stderr from the sub-process will be piped to the current process' stdout and stderr. Any input in this processes stdin will be piped to the sub-process' stdin

        Content sent to standard error by the command will be forwarded to standard error for this JVM.

        This method blocks on the execution of the command.

        Example Usages:

           Shell.execWithPipe( "read \"are you there?\"" )
         

        Throws:
        CommandFailedException - if the process finishes with a non-zero return value
      • processWithHandler

        public void processWithHandler​(ProcessStarter.ProcessHandler handler)
        Deprecated.

        Executes the given command as if it had been executed from the command line of the host OS (cmd.exe on windows, /bin/sh on *nix) and calls the provided handler with the newly created process.

        NOTE: In gosu, you should take advantage of the block-to-interface coercion provided and pass blocks in as the handler. See the examples below.

        Parameters:
        handler - the process handler for this process.
      • getEnvironment

        public Map<String,​String> getEnvironment()
        Deprecated.
        Returns a modifiable string map view of this process' environment. Whenever a process starter is created, the environment is initialized to a copy of the current process environment (see System.getenv()). Subprocesses subsequently started by this object will use this map as their environment.

        The returned object may be modified using ordinary Map operations. These modifications will be visible to subprocesses. Two ProcessStarter instances always contain independent process environments, so changes to the returned map will never be reflected in any other ProcessStarter instance or the values returned by System.getenv. There are many system-dependant restrictions placed on the returned map. See ProcessBuilder for more information

        Returns:
        This process environment
        Throws:
        SecurityException - If a security manager exists and its checkPermission method doesn't allow access to the process environment
        See Also:
        ProcessBuilder, System.getenv()
      • getDirectory

        public File getDirectory()
        Deprecated.
        Returns this process' working directory. Subprocesses subsequently started by this object will use this as their working directory. The returned value may be null -- this means to use the working directory of the current Java process, usually the directory named by the system property user.dir, as the working directory of the child process.

        Returns:
        This process's working directory
      • setDirectory

        public void setDirectory​(File directory)
        Deprecated.
        Sets this process' working directory. Subprocesses subsequently started by this object will use this as their working directory. The returned value may be null -- this means to use the working directory of the current Java process, usually the directory named by the system property user.dir, as the working directory of the child process.

        Parameters:
        directory - This process' working directory
      • withCMD

        public ProcessStarter withCMD()
        Deprecated.
        The process built up will use CMD if this is a windows platform. This is necessary because on windows certain basic commands such as "dir" are not programs, but rather are built into CMD. Thanks, Microsoft.
      • includeStdErrInOutput

        public ProcessStarter includeStdErrInOutput()
        Deprecated.
        If called, this ProcessStarter will include the StdErr output in the return string of this process. Note that this has no effect if withStdErrHandler(OutputHandler) is called.
        Returns:
        this object for chaining
      • doNotThrowOnNonZeroReturnVal

        public ProcessStarter doNotThrowOnNonZeroReturnVal()
        Deprecated.
        If called, this ProcessStarter will not throw an exception if the underlying process exits with a non-zero return code
        Returns:
        this object for chaining
      • withStdErrHandler

        public ProcessStarter withStdErrHandler​(ProcessStarter.OutputHandler stdErrHandler)
        Deprecated.
        Parameters:
        stdErrHandler - handler that will be called with every line of output to stderr
        Returns:
        this object for chaining
      • withStdOutHandler

        public ProcessStarter withStdOutHandler​(ProcessStarter.OutputHandler stdOutHandler)
        Deprecated.
        Parameters:
        stdOutHandler - handler that will be called with every line of output to stdout
        Returns:
        this object for chaining