i want to code a manager program in java which will execute a c program and can read it’s input stream and write to output stream.
the client will request c exe then server will handle it’s request like following :
- the manager program will execute.
- it’ll execute a c program.
- can send c program’s output to browser.(input stream).
- should be able to accept input from browser and supply to c program.
i have tried executing c code using Runtime and Process. but it gives exception
---------------------------
16 bit MS-DOS Subsystem
---------------------------
Error while setting up environment for the application. Choose 'Close' to terminate the application.
---------------------------
Close
---------------------------
help?
code :
import java.io.*;
class Dev
{
public static void main(String args[])
{
try
{
Process p = Runtime.getRuntime().exec("dev.exe");
InputStream is = p.getInputStream();
// from her i'll do the stuff but it gives error.
}
catch(Exception e)
{
System.out.print("\n\n\t Error : "+e);
}
}
}
You can execute a program by creating a class that implements
Runnable, then passing it aProcess, which is described in this answer. The answer there also describes how to get the process’s output in anInputStream. As for passing in some input, this can be done by piping a string in the command line. On theProcess-making line from that answer, you can add:This will pipe the value of
someInputtocommand. This is based on the command line and is technically platform specific, but should work without changes on Linux, OS X, and Windows.