【问题标题】:Run A .sh script from java从 java 运行一个 .sh 脚本
【发布时间】:2014-03-15 01:53:57
【问题描述】:

我有一个游戏,我将启用自动重启功能。它每 24 小时发生一次,这很容易制作。但是,问题是,我不知道如何打开运行“run.sh”(执行 Java 游戏服务器)。

代码将首先关闭所有内容,在调用 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...

【问题讨论】:

标签: java linux terminal runtime sh


【解决方案1】:

尝试转义字符串:

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

【讨论】:

    【解决方案2】:

    不错的m8游戏是你自己做的!!?

    也在这里:^)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-29
      • 2013-01-29
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多