• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i compile c/c++ code with java?  RSS feed

 
David Wong
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use java for compiling c/c++ code,and the compiled infomation should be caught,e.g overflow...Is there a way to carry out this?I used getRuntime().exec("gcc .c -o .exe"),on this condition there was no information from compiling time.

How can i use java to control that one executable program(e.g .exe) not to access the files out of this folder/directory,and assure the program not
to performance anything in high-risk command like system("reboot") or while(1) fork();Is that possible for java?

If c/c++ could be better to do this,welcome as well.


thanks so much!!!
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have asked several questions here, overflow is not 'caught' by the compiler. Java can run compiler, yes, but what you are ( appparently ) investigating is an issue that was fixed in Java in the design of the language. What are you trying to do?

It sounds like you have been reading about the array bounds overflow issue and are trying to learn C/C++ and Java and make a decision about which to study. If that is so, study Java first because of it's rich collection of computer science, then study C/C++ as an adjunct when and if you have the extra time.

There are many computer languages, most programming styles can be done in most languages. How many languages do you know right now?

Welcome to Java Ranch Saloon
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't completely answer your question, but if you haven't read it already, you could learn much from When Runtime.exec () wont.
[ May 04, 2008: Message edited by: Darryl Burke ]
 
David Wong
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Jordan:
What are you trying to do?

study Java first because of it's rich collection of computer science, then study C/C++ as an adjunct when and if you have the extra time.

How many languages do you know right now?

Welcome to Java Ranch Saloon


thanks for information.
In fact I am trying to build a web project:The c/c++ code is submitted and forwarded to the server from client browser.Then I think there would be a method in java can invoke and run c/c++ compiler,after compiling then get compiler information if something was wrong in code that can't pass the compiling.In a word,that will be an online judge system.

I know c/c++ a little.I just want to use Java to carry out this question.I am studying Java now.

thanks again.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen two or three 'compiler on the web' - it can be done.

Be sure to look at what Darryl posted, it will save you a lot of wasted time. I still need to absorb it myself. If you get it working, provide me with your suggestions.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a similar challenge last year, and my solution was here. Using ProcessBuilder would probably have given a better solution.
 
Tim Holloway
Saloon Keeper
Posts: 18797
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.exec is a potential security issue since the commands it invokes are running under the same security context as the JVM of the Java application that's doing the Runtime.exec. On a web server that can be very broad, depending on how competent/paranoid the sysadmin is. A security wrapper can help manage that, but that's a pretty advanced thing to do.

When you run a program like gcc, there are actually TWO text outputs that come back - stdout and stderr. Typically you'll want to see both of them. Runtime.exec can capture these streams, but then it's up to the Java app to figure out how to present them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!