A better way to execute a series of external commands?
Hi,
Consider the code snippet...
Process proc1 = rt.exec("Some external command");
...
Vector vecOutput = outputGobbler.getOutput() ;
String[] strAlterCmds = new String[vecOutput.size()];
for ( int k = 0 ; k < vecOutput.size() ; k++ )
{
strAlterCmds[k] = new String();
strAlterCmds[k] = "cmd.exe /c blah.... " +(String) vecOutput.elementAt( k )+ " ;
Process proc2 = rt.exec(strAlterCmds[k], null);
StreamGobbler errorG = new
StreamGobbler( proc2.getErrorStream(), "Error") ;
StreamGobbler outputG = new
StreamGobbler( proc2.getInputStream(), "Output") ;
errorG.start() ;
outputG.start() ;
int exitVal1 = proc2.waitFor();
}
The second part of the execution is taking AGES and I am not sure forking a new process for runtime execution is the best alternative here.
I would be glad if someone can point me to a smarter solution.
In short: I intend to execute a series of commands using RTE depending on the values I get in the loop.
Thanks.