FileDocCategorySizeDatePackage
CLIProcessExecutor.javaAPI DocGlassfish v2 API3980Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

CLIProcessExecutor

public class CLIProcessExecutor extends Object
CLIProcessExecutor A simple process executor class that is used by CLI.
author
jane.young@sun.com
version
$Revision: 1.6 $

Fields Summary
Process
process
Constructors Summary
public CLIProcessExecutor()

        process = null;
    
Methods Summary
public voidexecute(java.lang.String[] cmd, boolean wait)
This method invokes the runtime exec

param
cmd the command to execute
param
wait if true, wait for process to end.
exception
Exception

        process=Runtime.getRuntime().exec(cmd);
            //process = new ProcessBuilder(cmd).start();
            
        // start stream flusher to push output to parent streams and null.
        StreamFlusher sfErr=new StreamFlusher(process.getErrorStream(), System.err, null);
        sfErr.start();

        // set flusher on stdout also, if not could stop with too much output
        StreamFlusher sfOut=new StreamFlusher(process.getInputStream(), System.out);
        sfOut.start();
        try {
            // must sleep for a couple of seconds, so if there is a jvm startup error,
            //the parent process
            //is around to catch and report it when the process in executed in verbose mode.
            Thread.currentThread().sleep(5000);
            //wait is not required for command like start database
            //where the process does not return since start database
            //spawn it's own process.
            if (wait) {
                process.waitFor();
            }
        }
        catch (InterruptedException ie) {
        }
    
public intexitValue()
return the exit value of this process. if process is null, then there is no process running therefore the return value is 0.

        if (process == null) return -1;
        return process.exitValue();