Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-06-2007, 11:41 AM
Member
 
Join Date: Nov 2007
Posts: 1
Rep Power: 0
Amit Kr. Mishra is on a distinguished road
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

Code:
import java.io.*;

class CompileCppFile{
File file;

CompileCppFile(File file){
this.file = file;
}

public void compile(){
try{
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? http://www.java-forums.org/images/smilies/confused.gif
:confused:

Process p= Runtime.getRuntime().exec( cmd, null, new File( file.getParent()) );

/*
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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the last modified date of a file from a java program Java Tip java.io 0 04-04-2008 03:45 PM
How to execute an External Program through Java program Java Tip java.io 0 04-04-2008 03:40 PM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 10:33 PM
getting problem in compiling java program? sathish04021984 New To Java 3 07-30-2007 10:26 AM
writing to a excel file from java program priyankabhar New To Java 1 07-10-2007 09:05 PM


All times are GMT +2. The time now is 11:43 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org