0

I want to launch a task in background and redirect all outputs to a file. For this, I do ./main.py > /tmp/logsFile 2>&1 & but i doesn't work I think the problem comes from the background task, when I do this but not in background, it works ! The problem when it's in background is that the file is created but empty and my bot always return things at the connection so the file should not be empty ! I have a MSI CX62 6QD 249XFR with Ubuntu 18.04 LTS on i3

EDIT: The command above works with a basic .sh with echo but no with main.py

3
  • It may be due to output buffering. Try some solutions here: stackoverflow.com/questions/107705/disable-output-buffering Jul 18, 2018 at 5:08
  • It work, thank you How do I mark this post resolved ?
    – Kureteiyu
    Jul 18, 2018 at 7:42
  • If it works, then please describe how you solved it in an answer to your question. That closes the question and leaves a reference for future users. It is perfectly fine here to answer your own question.
    – vanadium
    Jul 18, 2018 at 8:27

1 Answer 1

5

I solved the problem by add the -u argument to the command who launches my python script. The command is now python3 -u main.py > /tmp/thebotlogs 2>&1 &
Apparently, it's the output buffering so the -u argument disable it
Thank you for your answers :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .