Please help me!!!

Thread Solved

Join Date: Jul 2007
Posts: 18
Reputation: vijaygandhi559 is an unknown quantity at this point 
Solved Threads: 0
vijaygandhi559 vijaygandhi559 is offline Offline
Newbie Poster

Please help me!!!

 
0
  #1
Jul 6th, 2007
Hi,

I am running an utility from java. The utility is a '.cmd' file. I have used the code below to run the utility.
  1. Runtime runTime = Runtime.getRuntime();
  2. try{
  3. runTime.exec("cmd /c start D:/Test/run.cmd");
  4. }
  5. catch(Exception e){

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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Please help me!!!

 
0
  #2
Jul 6th, 2007
Look at the Process class and its exitValue() method.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 18
Reputation: vijaygandhi559 is an unknown quantity at this point 
Solved Threads: 0
vijaygandhi559 vijaygandhi559 is offline Offline
Newbie Poster

Re: Please help me!!!

 
0
  #3
Jul 6th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,189
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 483
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Please help me!!!

 
1
  #4
Jul 6th, 2007
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.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Please help me!!!

 
0
  #5
Jul 6th, 2007
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:
  1. Runtime runTime = Runtime.getRuntime();
  2. try{
  3. int exitCode = 0;
  4. for ( int runCount=0; runCount<5 && exitCode==0; runCount++ ) {
  5. // set whatever you need in properties file here
  6.  
  7. Process cmdProcess = runTime.exec("cmd /c start D:/Test/run.cmd");
  8. cmdProcess.waitFor();
  9. exitCode = cmdProcess.exitValue(); // will be 0 if successful
  10. }
  11. // if exitCode != 0 here, your process failed, so do whatever you need to do for that case
  12. } catch(Exception e){
  13.  
  14. }

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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 18
Reputation: vijaygandhi559 is an unknown quantity at this point 
Solved Threads: 0
vijaygandhi559 vijaygandhi559 is offline Offline
Newbie Poster

Re: Please help me!!!

 
0
  #6
Jul 7th, 2007
Thanks for the help , that's what i was looking for. hope it should resolve the issue. Thank you very much
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Please help me!!!

 
1
  #7
Jul 7th, 2007
And you got it in the first post.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 18
Reputation: vijaygandhi559 is an unknown quantity at this point 
Solved Threads: 0
vijaygandhi559 vijaygandhi559 is offline Offline
Newbie Poster

Re: Please help me!!!

 
0
  #8
Jul 31st, 2007
Hi ...when i use the above code exactly ,
  1. 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();
  2. try{
  3. int exitCode = 0;
  4. for ( int runCount=0; runCount<5 && exitCode==0; runCount++ ) {
  5. // set whatever you need in properties file here
  6.  
  7. Process cmdProcess = runTime.exec("cmd /c start D:/Test/run.cmd");
  8. cmdProcess.waitFor();
  9. exitCode = cmdProcess.exitValue(); // will be 0 if successful
  10. }
  11. // if exitCode != 0 here, your process failed, so do whatever you need to do for that case
  12. } catch(Exception e){
  13.  
  14. }
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 18
Reputation: vijaygandhi559 is an unknown quantity at this point 
Solved Threads: 0
vijaygandhi559 vijaygandhi559 is offline Offline
Newbie Poster

Re: Please help me!!!

 
0
  #9
Jul 31st, 2007
.
Last edited by vijaygandhi559; Jul 31st, 2007 at 2:04 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,357
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 252
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Please help me!!!

 
0
  #10
Jul 31st, 2007
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
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC