我有一个我想在启动时运行的java代码, 但我希望能够看到CMD上运行的代码。(就像我手动运行java一样)
我该怎么做?
这就是我在rc.local中所拥有的
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address - this was in the default - didn't touch it..
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
# run the java file from desktop
sudo java -jar Desktop/test.jar &
exit 0
谢谢,
答案 0 :(得分:0)
从我看到的,你必须选择。
首先你可能需要在下一个命令之前等一下,女巫是exit 0
并且肯定会退出,执行自己。像这样你就有时间阅读输出。
尝试添加sleep 1m
befor exit 0
如果需要,你可以在谷歌上找到关于这个命令的更多信息,但是1分钟的例子是1分钟
其他解决方案是改变你的java程序以等待用户输入,例如:
System.out.println("\n Hit Return to exit... ");
String kS = scan.nextLine();
System.exit(0);
像这样的java编程。会等到你按回车。
希望你能找到最适合自己的东西。