必须在bash中使用nohup命令击中输入

发布于 2025-02-08 12:13:52 字数 446 浏览 1 评论 0原文

我正在尝试使用以下nohup命令来运行Java Springboot服务器。

nohup java -jar webservices-0.0.1-SNAPSHOT.jar > nohup.out 2>&1 &

但是运行此操作后,我将获得以下输出&我必须点击Enter才能运行后续命令。

$ + nohup java -jar -dspring.config.config.additional-location = config/application-dev.properties webservices-0.0.1-snapshot.jar

无论如何是否在bash中避免这种情况?

I'm trying to run a java springboot server using the following nohup command.

nohup java -jar webservices-0.0.1-SNAPSHOT.jar > nohup.out 2>&1 &

But after running this, I'm getting the following output & I have to hit enter to run the subsequent commands.

$ + nohup java -jar -Dspring.config.additional-location=config/application-dev.properties webservices-0.0.1-SNAPSHOT.jar

Is there anyway to avoid this in bash?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦与时光遇 2025-02-15 12:13:52

看来您的shell调试跟踪(set -x模式)已打开,这意味着bash将在执行每个命令之前打印每个命令(但在扩展变量等之后)。由于nohup java ...命令是背景的,因此这是异步发生的,并且恰好在之后被打印出 都打印了其提示 是“ + nohup java ...(debug trace)。

”(您的shell提示),然后 但是,由于该跟踪是由外壳打印的,而不是命令本身,因此重定向不适用。)

您实际上不需要返回。不与Debug Tracing混合)提示,您可以像正常的那样输入另一个命令

。 ,我认为您的主要选项是在运行命令之前关闭调试跟踪(set +x),或在shell打印下一个提示之前添加延迟:

nohup java -jar webservices-0.0.1-SNAPSHOT.jar > nohup.out 2>&1 & sleep 1

在这里,nohup java ...命令像往常一样在后台运行,但是sleep 1命令在前景中运行,因此shell不会打印下一个提示是时候进行背景过程打印其调试跟踪的时间)。

It looks like you have shell debug tracing (set -x mode) turned on, meaning bash will print each command before executing it (but after expanding variables etc). Since the nohup java ... command is backgrounded, this happens asynchronously, and happens to get printed after the shell has printed its prompt, so you get "$" (your shell prompt) followed by "+ nohup java ... (the debug trace).

(Note: you have errors & output from the command redirected to nohup.out, but since the trace is printed by the shell, not the command itself, the redirect doesn't apply.)

You don't actually need to press return at this point; the only thing pressing return does is get you a new, clean (not mixed with debug tracing) prompt. You could just enter another command as normal. However, since the shell is confused about where on the line you are, features like command editing and history recall may not work properly.

If you want to avoid this, I think your main options are to either turn off debug tracing (set +x) before running the command, or add a delay before the shell prints its next prompt:

nohup java -jar webservices-0.0.1-SNAPSHOT.jar > nohup.out 2>&1 & sleep 1

Here, the nohup java ... command runs in the background as usual, but the sleep 1 command runs in the foreground and so the shell won't print its next prompt for a second (which should be enough time for the background process to print its debug trace).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文