Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

launch .exe file from a java program 1

Status
Not open for further replies.

dilse

Programmer
Jul 21, 2001
6
IN
I would like to know the detail syntax for launching an .exe file (written in c ) from inside a java program .
Please give some help.

 
Hi dilse,

Taking for example your .exe file is named "abc.exe" and is in the same folder as your java program:-

import java.io.*;
public class example1
{
public static void main(String[] args)
{
Runtime rt = Runtime.getRuntime();
try {
Process extProcess = rt.exec("abc");
extProcess.waitFor();

// receive the output of external program
InputStream extInput = extProcess.getInputStream();
int bytesAvailable = extInput.available();
if (bytesAvailable > 0)
{
byte[] extInputData = new byte[bytesAvailable];
extInput.read(extInputData);
System.out.println(new String(extInputData));
}
}
catch (Exception e)
{
}
}
}

If you C program requires input from the user, the program will "hang" as the C program's console will be "hidden" so you will never be able to enter anything into the C program.

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top