Nejib hanchi
Nejib hanchi

Reputation: 1

commande console form java

i'm trying to execute 2 commands via java programme with process

Process p  = Runtime.getRuntime().exec(command1);
Process p2 = Runtime.getRuntime().exec(command2);

the problem is that the first one is ok but the seconde on cant be established it is always bloqed in waitfor()

Upvotes: 0

Views: 53

Answers (2)

Omry Yadan
Omry Yadan

Reputation: 33596

When running an external procss that prints anything to stdout/stderr, you should read what it writes - otherwise it will block once it's buffer fills up. you basically needs a thread to read from stdout and a thread to read from stderr of each process.

Upvotes: 1

KathyA.
KathyA.

Reputation: 681

You might be running into the dreaded "need to empty the streams" problem. See When Runtime.exec() won't for details on it.

Also in the same article is some info on other traps you can run into if you're treating getRuntime().exec() like the command line.

Upvotes: 1

Related Questions