英文:
nohup doesn't write anything to file
问题
我有一个Java程序,它执行以下Shell脚本来重新启动自己。
sleep 5
nohup java -jar /home/my-dir/MyJar.jar &
如果我从终端运行脚本,它会按预期工作。但是,如果Java程序执行该脚本,程序会正常启动,但没有任何内容写入输出文件。
我通过以下代码启动脚本:
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("/bin/sh", "/home/my-dir/start.sh");
try {
processBuilder.start();
logger.info("成功启动");
} catch (IOException e) {
e.printStackTrace();
}
英文:
i have a Java program which executes the following shell script to restart it self.
sleep 5
nohup java -jar /home/my-dir/MyJar.jar &
If i run the script from a terminal, it just works as expected. However if the Java Program executes the script, the program starts normally but nothing gets written to the output file.
I start the script via the following code
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("/bin/sh", "/home/my-dir/start.sh");
try {
processBuilder.start();
logger.info("Successfully started");
} catch (IOException e) {
e.printStackTrace();
}
答案1
得分: 0
以下命令对我有效。它会将所有输出写入指定的文件。
nohup java -jar /home/my-dir/MyJar.jar > /home/my-dir/log.txt & tail -f /home/my-dir/log.txt &
英文:
Following command worked for me. It writes all the output to the specified file.
nohup java -jar /home/my-dir/MyJar.jar > /home/my-dir/log.txt & tail -f /home/my-dir/log.txt &
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论