I was developing a simple C code generator in java in Linux and i wanted my java program to automatically compile and run the generated C code,i.e. the .out file. Though i have been able to compile it successfully I am not able to run the compiled object code. Can anyone please write the code to suggest how to execute the C code using the java program.
-
2How about you show us what you have tried and we can help you instead of asking us to do the work for you?unholysampler– unholysampler2011-11-03 17:55:20 +00:00Commented Nov 3, 2011 at 17:55
-
The script file contains code for compiling. Process p=Runtime.getRuntime().exec("/home/jerisalan/Documents/workspace/CodeGenerator/script.sh /home/jerisalan/Documents/workspace/CodeGenerator/output.c"); Process r=Runtime.getRuntime().exec("/home/jerisalan/Documents/workspace/CodeGenerator/./output.out");Jeris– Jeris2011-11-03 18:10:37 +00:00Commented Nov 3, 2011 at 18:10
-
How did u solve your problem? Im facing the same problem.Pheonix7– Pheonix72016-01-22 11:20:48 +00:00Commented Jan 22, 2016 at 11:20
Add a comment
|
1 Answer
If you're successfully creating the .out file, then you should be able to run it with one of the Runtime#exec functions:
Runtime.getRuntime().exec("./a.out");
...or (more control) via the stuff in the Process class. The Process class stuff lets you do things like control the input and output (via streams).
2 Comments
Jeris
I have added it to my code but the execution does not start...what can it be due to???
T.J. Crowder
@jerisalan: About 150 things, you'll have to show your code. It's very hard to help with coding problem without code.