2014-02-15 170 views
1

我有一款遊戲,我將啓用自動重新啓動功能。它每24小時發生一次,這很容易做到。但是,問題是,我不知道如何打開運行「run.sh」(它執行Java遊戲服務器)。從java運行.sh腳本

代碼將首先關閉所有內容,在System.exit被調用之前,它應該在新的終端中打開run.sh。我將如何做到這一點?

這是我目前使用的方法,但它給了我這個錯誤。

public static boolean start() { 
     try { 
      List<String> command = new ArrayList<String>(); 
      command.add("cd /root/Dropbox/[SALLESY] 742 Server"); 
      command.add("java -Xmx1024m -Xss2m -Dsun.java2d.noddraw=true -XX:+DisableExplicitGC -XX:+AggressiveOpts -XX:+UseAdaptiveGCBoundary -XX:MaxGCPauseMillis=500 -XX:SurvivorRatio=16 -XX:+UseParallelGC -classpath bin:data/libs/* com.sallesy.Application"); 
      ProcessBuilder builder = new ProcessBuilder(command); 
      Process proc = builder.start(); 
      BufferedReader read = new BufferedReader(new InputStreamReader(
        proc.getInputStream())); 
      try { 
       proc.waitFor(); 
      } catch (InterruptedException e) { 
       System.out.println(e.getMessage()); 
      } 
      while (read.ready()) { 
       System.out.println(read.readLine()); 
      } 
     } catch (Exception e) { 
      System.out.println(e.getMessage()); 
      return false; 
     } 
     return true; 
    } 

錯誤:

sh script.sh 
Cannot run program "cd /root/Dropbox/[SALLESY] 742 Server": error=2, No such file or directory 
Could not start a new session... 
+0

http://stackoverflow.com/questions/525212/how-to-run-unix-shell-script-from-java-code – celezar

回答

0

嘗試逃避字符串:

"cd /root/Dropbox/\[SALLESY\]\ 742\ Server" 
-1

不錯的遊戲M8沒有ü使它urself!?

也在這裏:^)

"cd /root/Dropbox/\[SALLESY\]\ 742\ Server"