我知道您可以使用以下命令通过Bash终端运行脚本:
ssh -n -f user@host "sh -c 'nohup /path/to/file/test.sh > /path/to/file/test.out 2>&1 &'"
当我们使用以下java命令运行同一命令时:
Runtime.getRuntime().exec( "comand" ).waitFor();
它不起作用。为了测试这个,我运行一个简单的.sh脚本打印“hello world”并将其输出到'test.out'文件。我没有收到运行时错误,我只是没有看到输出。
注意:我在“命令”区域中正确放置了'\'转义字符。
我们如何使用java做到这一点?
答案 0 :(得分:0)