无法在屏幕上运行.py脚本

时间:2019-07-17 07:19:32

标签: python linux gnu-screen

我正在尝试在Linux屏幕上运行.py脚本。创建屏幕后,我将目录更改为脚本的位置,然后尝试运行它: python script_name.py,但没有收到回复。您能建议如何解决吗?预先谢谢你。

我试图:

  1. screen -S screen_name
  2. cd location_of_the_script
  3. python script_name.py

我想让我的脚本在屏幕上运行,然后脱离该屏幕。

2 个答案:

答案 0 :(得分:0)

screen -S <name>(为屏幕命名)

screen -r <name>(如果未附加,则应附加,但应该附加)

cd /location/of/script(进入您的脚本)

python your_script.py(运行脚本)

^a d,即Ctl + a,然后是d(与屏幕分离)

这里是Linux屏幕备忘单的链接: http://aperiodic.net/screen/quick_reference

我还建议使用tmux代替Linux屏幕。

答案 1 :(得分:0)

最好运行byobu而不是screentmux,因为它提供了附加的系统信息,您仍然可以选择选择screen作为后端。

$ byobu
$ cd /location/of/python/script
$ python script.py

然后按 F6 Ctrl - a ,然后按 d 即可分离。

注意:无论是否收到响应,都将完全取决于您的脚本。 要确定它是否正在运行,您可以尝试使用ps -u root | grep script.pytime python script.py之类的工具,将运行时打印到std.out。