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?
CodePudding user response:
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).