Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

A better way to execute a series of external commands?

843798Jun 9 2005
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.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 7 2005
Added on Jun 9 2005
0 comments
90 views