hello friends,

I am running one _ant_compile.cmd through a java program,this is how i have done it,

File file=new File (path)//path is a parameter passed in
Runtime rt=Runtime.getRuntime();

      Process pr= rt.exec  (" rundll32 SHELL32.DLL,ShellExec_RunDLL " + file.getAbsolutePath());

so, as expected the _ant_compile.cmd gets executed, but after it's done before closing the console window it says "press any key to close" and requires the user to press a key. my problem is that....I need to get rid of that part and let it close anyways. so since I cannot meddle with the _ant_compile.cmd file I have to get the key pressed when that message comes up, without the interaction of the user. So I thought of getting the output of the process to a String variable and cheking for the necessary line in order to fire the button press action... how to get the process output to a String (or even maybe write to a file)??

Recommended Answers

All 5 Replies

how to get the process output to a String

There are methods to get I/O Streams for the process you are running.
Have you tried reading what the process has written to a stream and writing to the stream that the process is reading from?

As this problems is related to cmd, did you try writing "exit" at the end of the file. Because it closes the window. If not then automatic key press can be done using a robot class. After the execution is done you can select a key to be pressed quickly. Hope this helps.

As this problems is related to cmd, did you try writing "exit" at the end of the file. Because it closes the window. If not then automatic key press can be done using a robot class. After the execution is done you can select a key to be pressed quickly. Hope this helps.

exactly....that's what I am trying to do, the problematic part is to catch the moment the program stops. the program stops with a specific line and waits for the users response...my idea is to get the output of the program to a text file or a string variable and check until I find that specific line, once I find it I can fire a button press....but now I'm stuck with not knowing how to get the output to somewhere else as the program executes...any ideas?

There are methods to get I/O Streams for the process you are running.
Have you tried reading what the process has written to a stream and writing to the stream that the process is reading from?

are you referring to pipes?

No, see the API doc for the Process class. It has methods to get I/O Streams from/to the process

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.