2

I ssh into an ubuntu 12.04 cloud server and start a web server like this (w/ bash):

$ nohup python tserver.py &
[2] 2122
$ nohup: ignoring input and appending output to `nohup.out'

After I run that command the prompt disappears. There is just a blank line. I can get my prompt back by pressing "enter" -- i.e. after I hit enter I see $ again. But I want to script a few of these commands (turning on a few different web server instances). So I don't want to script something like "send enter command." What is going on here? Why do I lose my prompt? How do I script a series of such commands?

4

You're backgrounding the application, and the application is generating output. Your prompt is still there, it just has extra stuff being shown.

For example:

$ ( sleep 1 && echo hello ) &
[1] 24764
$ █

And then after a 1 second delay, I get:

$ ( sleep 1 && echo hello ) &
[1] 24764
$ hello
█

The echo is just writing output to your terminal, and appears where your cursor currently is. The shell doesn't know that output was shown. You can continue typing as if that output weren't there (it just becomes difficult to read).

However a clean solution to this would be to redirect the output:

nohup python tserver.py >/dev/null 2>&1 &
  • Aw man you are too quick :( – polym Jul 23 '14 at 14:28
1

Though you did start the program in the background by stating &, the output of the background process is still directed to the stdout of your current terminal.

That means your prompt is overwritten by something like a echo '\r\n' (overwrites the current line in case your next prompt is completely gone) or echo "Someotherstuff" (prints Someotherstuff infront of your prompt and then goes to the next line of your terminal).

If you press ENTER, you will just enter a newline, which makes your prompt be printed again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.