1

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.

3
  • 2
    How about you show us what you have tried and we can help you instead of asking us to do the work for you? Commented 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"); Commented Nov 3, 2011 at 18:10
  • How did u solve your problem? Im facing the same problem. Commented Jan 22, 2016 at 11:20

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

I have added it to my code but the execution does not start...what can it be due to???
@jerisalan: About 150 things, you'll have to show your code. It's very hard to help with coding problem without code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.