ソースコード判定ソフトを開発しています.UBuntu 12.04 LTSからLinuxプラットフォームで開発しました.
今、私はそれを Windows に展開したいと考えています。私のソフトウェアは、UNIXシェルに従ってコマンドを作成し、それらをファイルに保存してから、ファイルを介してコマンドを実行しています。コードの一部を次に示します。
package codejudge.compiler.languages;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import codejudge.compiler.TimedShell;
public class C extends Language {
String file, contents, dir;
int timeout;
public C(String file, int timeout, String contents, String dir) {
this.file = file;
this.timeout = timeout;
this.contents = contents;
this.dir = dir;
}
public void compile() {
try {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file)));
out.write(contents);
out.close();
// create the compiler script
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/compile.sh")));
out.write("cd \"" + dir +"\"\n");
out.write("gcc -lm " + file + " 2> err.txt");
out.close();
Runtime r = Runtime.getRuntime();
Process p = r.exec( dir + "/compile.sh");
p.waitFor();
p = r.exec(dir + "/compile.sh"); // execute the compiler script
TimedShell shell = new TimedShell(this, p, timeout);
shell.start();
p.waitFor();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void execute() {
try {
// create the execution script
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh")));
out.write("cd \"" + dir +"\"\n");
out.write("./a.out < in.txt > out.txt");
out.close();
Runtime r = Runtime.getRuntime();
Process p = r.exec(dir + "/run.sh");
p.waitFor();
p = r.exec(dir + "/run.sh"); // execute the script
TimedShell shell = new TimedShell(this, p, 3000);
shell.start();
p.waitFor();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Windowsで同じコードを実行すると、次のエラーが発生します(WindowsにminGWがインストールされています):
Codejudge compilation server running ...
Compiling garima.c...
java.io.IOException: Cannot run program "C:\xampp\htdocs\project\codejudge-compiler\stage\1/compile.sh": CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at codejudge.compiler.languages.C.compile(C.java:41)
at codejudge.compiler.RequestThread.run(RequestThread.java:65)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 6 more
java.io.FileNotFoundException: C:\xampp\htdocs\project\codejudge-compiler\stage\1\err.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at codejudge.compiler.RequestThread.compileErrors(RequestThread.java:90)
at codejudge.compiler.RequestThread.run(RequestThread.java:66)
java.io.IOException: Cannot run program "C:\xampp\htdocs\project\codejudge-compiler\stage\1/run.sh": CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at codejudge.compiler.languages.C.execute(C.java:65)
at codejudge.compiler.RequestThread.run(RequestThread.java:72)
Caused by: java.io.IOException: CreateProcess error=193, %1 is not a valid Win32 application
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 6 more
java.io.FileNotFoundException: C:\xampp\htdocs\project\codejudge-compiler\stage\1\out.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at codejudge.compiler.RequestThread.execMsg(RequestThread.java:106)
at codejudge.compiler.RequestThread.run(RequestThread.java:77)
私はwin32シェルコマンドについてほとんど知識がありません..コードにどのような変更を加える必要があるか. Windowsで実行されないコマンドはどれですか? そして、ウィンドウの代替は何ですか?