我想編譯一個輸入文本並使用一個託管bean和一個頁面.xhtml創建.exe文件。但是文件的創建就確定和.exe不到風度工作 這裏的創建管理bean代碼:在JSF中執行Cmd命令
package Servlets;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
@ManagedBean(name = "fichier", eager = true)
public class Fichier implements Serializable{
private String code;
private String error;
public String getCode() {
return code;
}
public String getError() {
return error;
}
public void setCode(String code) {
this.code = code;
}
public void setError(String error) {
this.error = error;
}
public void compile() throws IOException
{
File file = new File ("C:\\Users\\Rad1\\test.c");
PrintWriter ecrivain;
ecrivain = new PrintWriter(new BufferedWriter (new FileWriter(file)));
ecrivain.println(code);
System.out.print("ecrivain");
ecrivain.close();
try {
Runtime runtime = Runtime.getRuntime();
String[] cmd={"cmd.exe","/C gcc C:\\Users\\Rad1\\test.c -o C:\\Users\\Rad1\\test.exe"};
Process p = runtime.exec(cmd,null,null);
System.out.print("boucle try");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
try {
String line=null;
while((line = reader.readLine()) != null) {
error =error+ line + "\n";
}
} finally {
reader.close();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
catch (Exception e) {System.out.println("erreur d'execution"); }
}
}
你能提供生成的異常嗎?檢查** catalina.out **文件。問候。 – 2013-04-30 07:45:54