I need to compile and run a c++ program from java. I am using
Process a = Runtime.getRuntime().exec (“g++ -g function.cpp -o function”);
Process b = Runtime.getRuntime().exec (“./function”);
the problem is that the output I get from the c++ program is not correct but If I compile and run it myself in the command line it works just fine. The problem is Java and i dont know why.
Thanks a lot
Al,
There is one definite and one probable problem that I see here. The definite problem is that Runtime.exec() does not wait for the process to complete. So you will need to add
before calling b.
The possible issue is that depending on how you are invoking this application, the current working directory may not be where you think it is. So function.cpp may not exist.