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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.