Runtime.Exec with cmd and problem in waitFor
Hi
I am running
Process p1 = Runtime.getRuntime().exec("cmd /c start /min <some.exe> <args to exe>");
then I am checking
Int ExitVal = p1.waitFor;
If (ExitVal != 0) and so on.
However, the problem is that the p1.waitFor does not really block the thread. It returns 0 and the program continues even though the some.exe has still not completed its execution.
My guess is that Java is giving the exitcode of cmd.exe and not some.exe.
If this analysis is correct, I am stumped. How do I get the exit code of some.exe?
If my analysis is wrong, please help me in the right direction.
Regards
Shreekar
[682 byte] By [
Shreekara] at [2007-10-2 21:56:06]

Hi !
I am not a windows man so maybe I am wrong but as I remember the start command sends the execution in the background so the cmd program will exit as soon as this is done and with a return code of 0. On Linux one has similar with the & at the end of a command.
So to wait you have to remove the start keyword.
Thanks ostense...after removing the \start and \min switches, the thread is blocked and I am getting correct results.
However, the start switch means something else...
See http://www.computerhope.com/cmd.htm
and
http://www.computerhope.com/starthlp.htm
I dont understand why removing these switches made Java a good boy.
Meanwhile, I am testing the side effects of NOT using the min switch :)
Regards
Shreekar
Cf the switch /WAIT and the implication of its absence:
start /?
START ["title"] [/Dpath] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/WAIT] [command/program]
[parameters]
WAITStart application and wait for it to terminate
> "Enables a user to start a separate window in Windows
> from the MS-DOS prompt."
Again, I read it afterwards. However, another funny thing is happening now. Initially my command was
"cmd start /min (some.exe) (some args) > somefile.txt"
(I know I missed to show the output redirection in my original post.)
Then I removed "start /min", it is working as expected.
Then I removed the output redirection and now it hangs !!!
I put back the output redirection and it is working. Does the output redirection make it wait in some way and force it to exit gracefully?
Any ideas?