how to call a dos program from a java program
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   champoussin_stephane
Posted On:   Thursday, March 29, 2001 07:48 AM

I want to execute a program from a java program. Is it possible ? If it is possible, how can i do ? It would be cool if you can give me an example. The program i want to call is an .exe . The program is : code.exe the call is : code.exe "string to code" and it returns to stdout a string. So i want to call this program with a string and i want to get the result in a string. May be it is very simple but i don't know how to do. Your help is welcome. You can answer me at : stephane.champoussin@free.fr Thanks. Stéphane...    More>>

I want to execute a program from a java program. Is it possible ?
If it is possible, how can i do ?
It would be cool if you can give me an example.
The program i want to call is an .exe .

The program is : code.exe
the call is : code.exe "string to code"
and it returns to stdout a string.

So i want to call this program with a string and i want to get the result in
a string.

May be it is very simple but i don't know how to do.

Your help is welcome.

You can answer me at :
stephane.champoussin@free.fr

Thanks.

Stéphane...

   <<Less

Re: how to call a dos program from a java program

Posted By:   Ranjan_Sinha  
Posted On:   Thursday, March 29, 2001 08:47 PM

It is very simple to do this.
Create an opject of type Process.Get an Object of type Runtime.You can do this with the following code
Process p ;
Runtime r = Runtime.getRuntime();
p = r.exec(" Full Path of your Dos Application");
Now you can send input to the Dos program by sending a stream to p through getInputStream() and receiving the output through getOutPutStream(). It will be a good idea to have BuffereReader and BufferedWriter do the reading and writing part.

Re: how to call a dos program from a java program

Posted By:   John_Zukowski  
Posted On:   Thursday, March 29, 2001 08:46 AM

Look in the FAQ. The answer is already there with a working program.
About | Sitemap | Contact