import java.io.*;
public class chk
{
String className;
String command,command1,command2;
public String getMsg(String fileName,File Path1)
{
String dir;
command = "tcc "+fileName;
String output = executeCommand(command,Path1);
if(output.compareTo("")==0)
output = "Compilation Successfull!!";
return output;
}
private String executeCommand(String command,File Path1)
{
StringBuffer output = new StringBuffer();
Process p;
try
{
p = Runtime.getRuntime().exec(command,null,Path1);
p.waitFor();
BufferedReader reader1 = new BufferedReader(new InputStreamReader(p.getErrorStream()));
BufferedReader reader2 = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader1.readLine())!= null)
{
output.append(line + "\n");
}
while ((line = reader2.readLine())!= null)
{
output.append(line + "\n");
}
} catch (Exception e)
{
e.printStackTrace();
}
return output.toString();
}
public static void main(String args[])throws IOException
{
String x;
File dir=new File("D:\\test");
chk ob = new chk();
x = ob.getMsg("hello.c",dir);
System.out.println("OUtput : "+x);
}
}
ERROR從Java類編譯C文件
我試圖編譯從Java類中的C代碼。我正在使用Turbo C/C++編譯器,並且還設置了其路徑,即「C:/ TC/bin」,即使我的程序正在編譯時,我直接從命令提示符編譯它們,但是當我嘗試使用java文件編譯它時出現錯誤消息。幫幫我!!
@TonythePony我應該使用哪種編譯器在Windows上運行? – rick
MinGW很受歡迎(免費):http://www.mingw.org/ –
@TonythePony會解決這個問題嗎? – rick