2013-05-09 144 views
0

我正在開發一個源代碼判斷軟件。我在Linux平臺上開發了UBuntu 12.04 LTS。替代windows的unix shell命令?

現在我想在Windows上部署它。 我的軟件,我正在創建命令按照UNIX shell,將它們保存在一個文件,然後通過文件執行命令。 下面是代碼的一部分:

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(); 
     } 
    } 
} 

當我在窗戶我收到以下錯誤回報(IHAVE安裝在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 shell命令的知識。需要對代碼進行哪些更改即ie。哪些命令應該更改,哪些不能在Windows上運行?他們的窗戶替代物是什麼?

+0

正在使用cygwin一個選項嗎? – piokuc 2013-05-09 17:52:58

+0

真的沒用過嗎?即使我使用它,我將如何將請求重定向到cygwin? – shiven 2013-05-09 17:54:04

+0

你需要在cygwin shell中運行整個事情 – piokuc 2013-05-09 17:54:38

回答

0

安裝Cygwin時,請確保包含所有與Java編譯器相關的東西。在安裝Cygwin終端後會出現在桌面上,打開該終端。在這個終端上,你可以運行帶有bin,sbin,usr等目錄的完全虛擬化的Linux環境幾乎所有的Linux命令。而且,在cygdrive下你會得到windows驅動器。所以,試試吧!