wood burning stoves*
The moose likes Java in General and the fly likes How to close dos 'pause' command in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to close dos Watch "How to close dos New topic
Author

How to close dos 'pause' command in Java

pkinuk Buler
Ranch Hand

Joined: May 22, 2009
Posts: 63
Hi all,

I need to write a program to execute two xxx.cmd files. Because the last line in both of the command files have a 'pause' command (Please press any key to continue...). My task is run the program to execute them one by one. Because I can't modify the contents in both command files. Therefore I wrote a small program to run a command file.



Let's call the command file to be test.cmd.

My problem is the program seems to be deadlock after reading the first line message "this is test!". My question is what should I do to skip the 'pause' command so that I can get the "finish!" message without changing the content of the test.cmd file.

Thank you in advance!

The following is the Java code I used to execute the test.cmd file.



James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Untested - write a new line character to the Process stdin obtained from Process.getOutputStream(). You can perform the write just before the proc.waitFor(). You should then close() stdin.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
pkinuk Buler
Ranch Hand

Joined: May 22, 2009
Posts: 63
Thank you James Sabre! It worked
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

pkinuk Buler wrote:Thank you James Sabre! It worked


I have just noticed that you don't seem to start the error gobbler.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to close dos 'pause' command in Java