简体   繁体   English

从Java运行.sh脚本

[英]Run A .sh script from java

I have a game, and I am going to enable auto-restarting features. 我有一个游戏,并且我要启用自动重启功能。 It will happen every 24 hours, which is easy to make. 它每24小时就会发生一次,很容易做到。 However, the problem is, I don't know how to open run "run.sh" (which executes the Java Game Server). 但是,问题是,我不知道如何打开运行“ run.sh”(执行Java Game Server)。

The code is going to shut down everything first, and right before System.exit is called, it should open the run.sh in a new terminal. 该代码将首先关闭所有内容,并且在调用System.exit之前,它应该在新终端中打开run.sh。 How would I do this? 我该怎么做?

This is the method I am currently using, but it's giving me this error. 这是我目前正在使用的方法,但它给了我这个错误。

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

Error: 错误:

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...

尝试转义字符串:

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

Nice game m8 did u make it urself!!? 不错的M8游戏,您自己做到了!!?

also here :^) 也在这里:^)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM