And it runs the utility successfully, the utility should be run 5 times and that too depends upon the status of the utility , I mean, if the utility runs successfully in the first iteration I have to run the second. Now my problem is : How should i know from the command prompt utility that it has been run successfully or failed in order to run the next iteration. I want to know , if there is any way to read from the Dos prompt window.
Frens this is very urgent task assigned to me.
Help would be greatly appreciated.
Thanks for the reply , but the problem is ....I have to run the utility 5 times so i have kept it in the loop , before the utility is run for the first time ...it should read one properties file , and we need to change the attributes of properties file each time and run the utility . Now the problem is ....it is running 5 dos windows at a time , which should not, it should run only one instance of utility at a time, i'e only one dos window at a time . Thank you.
If you searched forum before you posted, you would find that just yeasterday I linked another post with same quastion to my post where I asked same thing few months ago with full elaboration of the problem. Here is link http://www.daniweb.com/forums/thread73182.html, enjoy reading and next time search before you post, there is huge possibility somebody already made a topic with same/similar problem
Last edited by peter_budo; Jul 6th, 2007 at 9:33 am.
As far as the cmd output and exit codes, see the thread that peter_budo posted a link to above. As for the loop, you can run it in the following loop based on exit code for success:
Process cmdProcess = runTime.exec("cmd /c start D:/Test/run.cmd");
cmdProcess.waitFor();
exitCode = cmdProcess.exitValue(); // will be 0 if successful
}
// if exitCode != 0 here, your process failed, so do whatever you need to do for that case
}catch(Exception e){
}
Note: This will still start five command windows, you can't get around that, but each will close before the other opens since you are using waitFor() and checking the exit value;
Last edited by Ezzaral; Jul 6th, 2007 at 1:21 pm. Reason: added note about cmd windows
Runtime runTime = Runtime.getRuntime();try{int exitCode = 0; for(int runCount=0; runCount<5 && exitCode==0; runCount++ ){// set whatever you need in properties file here Process cmdProcess = runTime.exec("cmd /c start D:/Test/run.cmd"); cmdProcess.waitFor(); exitCode = cmdProcess.exitValue(); // will be 0 if successful } // if exitCode != 0 here, your process failed, so do whatever you need to do for that case} catch(Exception e){ }Runtime runTime = Runtime.getRuntime();
Process cmdProcess = runTime.exec("cmd /c start D:/Test/run.cmd");
cmdProcess.waitFor();
exitCode = cmdProcess.exitValue(); // will be 0 if successful
}
// if exitCode != 0 here, your process failed, so do whatever you need to do for that case
}catch(Exception e){
}
it is starting the "run.cmd " command window...but the problem is , it is executing the statements below the code simultaneously......how to make the control stop there until my cmd window is finished.
Help will be greatly appreciated.
Last edited by vijaygandhi559; Jul 31st, 2007 at 2:17 am.
I'm not sure the code you posted there will even compile. You have a for block using a runCount variable inside of a try/catch block inside of a for block using a runCount varaiable (again) inside a try block with no catch block (at least not posted).
Clean that code up, first, then try to run it again, and if it still doesn't work, then ask again. And, once you do cmdProcess.waitFor(), any code below that point will not execute until the command has finished. Which, since you are not consuming the Streams of the process, might be never, if it produces enough output to fill the buffer.
Last edited by masijade; Jul 31st, 2007 at 2:54 am. Reason: typo
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.