0

How can I avoid python printing to the terminal when running in the background? I want it to print when run in the foreground or piped to another file, which it does successfully, but not print when run in the background.

For example, I have a file testing.py. With one line:
print("This is just a test")
If I run in the terminal
>python testing.py
It gives me:
This is just a test
However, if I run the script in the background,
python testing.py &
I still get
This is just a test
printed to the terminal, directly into my command prompt.

3
  • 3
    Where do you expect print() to send the text to if not the console? Commented Mar 22, 2018 at 14:16
  • You can pipe the output to dev/null, maybe? Commented Mar 22, 2018 at 14:16
  • This is really a question about the terminal shell, not python.
    – jaredad7
    Commented Mar 22, 2018 at 16:48

1 Answer 1

5

Do

python testing.py > /dev/null &

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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