【发布时间】:2014-02-09 20:19:32
【问题描述】:
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);
}
}
错误
我正在尝试从 java 类编译 C 代码。我正在使用 Turbo C/C++ 编译器,并且还设置了它的路径,即“C:/TC/bin”,即使我的程序在我直接从命令提示符编译它们时正在编译,但是当我尝试使用 java 文件编译它时,如下出现错误信息。救命!!
【问题讨论】:
-
@TonythePony 我应该使用哪个编译器在 Windows 上运行?
-
MinGW 很受欢迎(而且免费):mingw.org
-
@TonythePony 这会解决问题吗?
-
您不太可能遇到任何环境问题,因为您不需要 MS-DOS 子系统,但可能还有其他问题。
-
天哪,为什么你在 2014 年还在使用 16 位编译器!?
标签: java c windows compilation