0

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()

1
  • waitFor() waits for the process to finish execution. Are you sure the second process is actually designed to finish executing, rather than continue running? Commented Mar 25, 2014 at 16:58

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

or re-direct your processes stdout to something like /dev/null or a log file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.