Results 1 to 1 of 1
  1. #1
    Join Date
    Nov 2007
    Posts
    1
    Rep Power
    0

    Default 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 11:49 AM. Reason: Code placed inside [code] block

Similar Threads

  1. writing to a excel file from java program
    By priyankabhar in forum New To Java
    Replies: 15
    Last Post: 01-17-2014, 01:39 PM
  2. Replies: 0
    Last Post: 04-04-2008, 03:45 PM
  3. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  4. Replies: 0
    Last Post: 10-04-2007, 10:33 PM
  5. getting problem in compiling java program?
    By sathish04021984 in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •