gpt4 book ai didi

linux - Rqaspberry 在启动时运行 java 脚本并查看 cmd?

转载 作者:太空宇宙 更新时间:2023-11-04 12:05:50 24 4
gpt4 key购买 nike

我有一个 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

谢谢,

最佳答案

据我所知,您必须做出选择。

首先,您可能需要在下一个命令之前稍等片刻,女巫是 exit 0 并且肯定会退出,自行执行。这样您将有时间阅读输出。

尝试在 exit 0 之前添加 sleep 1m如果需要,您可以在谷歌上找到有关此命令的更多信息,但例如 1m 是 1 分钟

其他解决方案是稍微更改您的 java 程序以等待用户输入,例如:

System.out.println("\n Hit Return to exit... ");
String kS = scan.nextLine();
System.exit(0);

像这样的 java 程序。会等到你按回车。

希望你能找到最适合你的。

关于linux - Rqaspberry 在启动时运行 java 脚本并查看 cmd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50782859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com