简体   繁体   English

Raspberry Pi(python)在后台运行并重新打开打印输出

[英]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: 我从网上了解到,有几种方法可以在后台运行python程序:

  1. sudo python scriptfile.py&
  2. sudo python scriptfile.py , then Control + Z , then bg sudo python scriptfile.py ,然后按Control + Z ,然后是bg
  3. Using nohup 使用nohup
  4. Using screen 使用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. 但是,我想知道在执行前两个选项中的任何一个时,在再次关闭并重新打开SSH之后,是否可以通过print命令恢复python程序内部打印的内容。 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. 所以我运行python,开始看到我的打印命令输出,但是,如果我关闭SSH,即使程序仍在运行,我也需要重新启动它才能再次看到我的打印语句。

1) You should never run a script with sudo . 1)永远不要使用sudo运行脚本。 You could potentially destroy your system. 您可能会破坏系统。

2) Once your SSH session is closed all processes go with it. 2)一旦您的SSH会话关闭,所有进程都将随之进行。 That is unless you use nohup or screen as you have found. 除非您使用找到的nohupscreen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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