Results 1 to 1 of 1
- 11-06-2007, 10:41 AM #1
Member
- Join Date
- Nov 2007
- Posts
- 1
- Rep Power
- 0
Poblem in Compiling a c++ file from a java program...
// This is the program to Compile a c++ file from a java program, & get compiler generated files in the file's parent directory.
//problem is that though it neither generate err nor throws exception, yet doesn't compile, PLEASE HELP. or suggest any other solution
Java Code:import java.io.*; class CompileCppFile{ File file; CompileCppFile(File file){ this.file = file; } public void compile(){ try{ [COLOR="DarkRed"]String[] cmd = new String[4]; cmd[0] = "cmd.exe"; cmd[1] = "/C"; cmd[2] = "PATH = C:\\TC\\BIN"; //where C++ is installed. cmd[3] = "TCC " + file.getName(); //not working. but why? [url]http://www.java-forums.org/images/smilies/confused.gif[/url] :confused: Process p= Runtime.getRuntime().exec( cmd, null, new File( file.getParent()) );[/COLOR] /* String[] envp = new String[1]; envp[0] = "PATH = C:\\TC\\BIN"; Process p= Runtime.getRuntime().exec( cmd, envp, new File( file.getParent()) ); //has no effect */ BufferedReader err = new BufferedReader( new InputStreamReader(p.getErrorStream()) ); String line; while( (line = err.readLine()) != null) System.out.println(line); BufferedReader output = new BufferedReader( new InputStreamReader(p.getInputStream()) ); while( (line = output.readLine()) != null) System.out.println(line); } catch(Exception ioE){ System.out.println(ioE.getMessage()); ioE.printStackTrace(); } } } class CompileCpp{ public static void main(String args[]){ CompileCppFile c = new CompileCppFile(new File("F:/Amit/WorkHouse/Test.cpp")); c.compile(); } }Last edited by JavaBean; 11-06-2007 at 10:49 AM. Reason: Code placed inside [code] block
Similar Threads
-
writing to a excel file from java program
By priyankabhar in forum New To JavaReplies: 6Last Post: 03-15-2012, 04:29 PM -
How to get the last modified date of a file from a java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:45 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM -
getting problem in compiling java program?
By sathish04021984 in forum New To JavaReplies: 3Last Post: 07-30-2007, 09:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks