How to send command via python to running screen (Ubuntu 12.04)

人盡茶涼 提交于 2019-12-08 08:43:00

问题


I am on Ubuntu 12.04 LTS running Python 2.7. My Python code looks somewhat like this:

from os import system
system("screen -S session -X stuff 'commandhere'`echo -ne '\015'`")

But when I try to run it, it does not do anything. I was wondering whether it was possible to fix this, and if so, how?

I am trying to send a command to an active screen "session" where "commandhere" is the command.


回答1:


Have you tried subprocess.call() like this:

#!/usr/bin/python
import subprocess
subprocess.call(["screen", "-S", "session", "-X", "stuff", "'command here'`echo -ne '\015'`"])

Another idea: It might be best to just create a bash script to do the session manipulation stuff and just have Python then call the bash script.



来源:https://stackoverflow.com/questions/24481876/how-to-send-command-via-python-to-running-screen-ubuntu-12-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!