Java hangs even though shell script’s execution is completed
I'm trying to execute a script from within my java code. The execution of the script is over(it's pid is no more), but java is stuck on waitFor() method of the shell script process!. And yes, I'm reading output and error streams in 2 separate threads. Yes, they are being joined at the end(after waitFor()).
The aspect which makes this question relevant to this forum is, if I put the following line in the shell script(at the top), everything seems to work fine.
But still, magically enough, putting exec statement in the script makes java work!. Why??
How can I avoid that illogical exec statement in the script?.
exec has any other functionality here, other than redirection?
Dude - how are WE supposed to figure out what either your Java program or your shell script are supposed to be doing???
Yes, it's possible to call a shell script from a Java program. Easy, in fact!
Yes, generally, you should be able to see anything that's printed to stderr or stdout.
And yes, you should be able to redirect stderr and/or stdout to a file.
1. Try reproducing the problem with a "simple-as-possible" test program
2. If, at that point, you still can't figure out, then post the COMPLETE contents of your (small!) test program and (even smaller!) script.
Posted the link for the benefit of others, if they ever face such a situation.
You're just asking a bunch of vague questions and making a bunch of totally unwarranted guesses.
Not the best way to solve a problem, IMHO.
My suggestion remains: try to reproduce the problem with a minimal test case, then DETERMINE what the problem is. Don't GUESS.
While you're at it, you might want to look into "buffered I/O'.
Why it's a Good Thing.
And why it might lead to sometimes "unexpected" results.
1. "stdout" (stream 1) is buffered; "stderr" (stream 2) isn't.
Try writing to stderr instead of stdout in your program and see if you get different results.
2. When a program ends (*really* ends), all buffered output is flushed (unless, of course, it terminates abnormally)(which is probably not the case here).
In any case, try to THINK about what you're doing. Don't just arbitrarily throw stuff at the wall and jump to false conclusions
about what happens to stick.
IMHO .. PSM
I don't think I'm "throwing stuff at the wall and jumping to false conclusions".
Nevertheless I thank you for your time and response. Appreciate it.
I had a good discussion with other guys, ultimately got a solution.
Please see the solution here.
Hi, pavanlimo -
Thank you for the followup, and sorry if I was a bit hard on you :(
More important, I'm glad you're squared away :)
Sincerely .. PSM
|All times are GMT -5. The time now is 05:26 AM.|