简体   繁体   中英

Raspberry Pi (python) Run in background and reopen print output

I have learned online that there are several ways of running a python program in the background:

  1. sudo python scriptfile.py&
  2. sudo python scriptfile.py , then Control + Z , then bg
  3. Using nohup
  4. Using screen

However, I would like to know if when doing any of the first two options, after I close and reopen SSH again, I can recover what the python program is internally printing by the print commands. So I run python and I start to see my print commands output, but if I close the SSH, even though the program is still running, I need to restart it in order to again see my print statements.

1) You should never run a script with sudo . You could potentially destroy your system.

2) Once your SSH session is closed all processes go with it. That is unless you use nohup or screen as you have found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM