问题描述
我在运行Python 2.7的Ubuntu 12.04 LTS上.我的Python代码看起来像这样:
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?
我正在尝试将命令发送到活动屏幕会话",其中"commandhere"是命令.
I am trying to send a command to an active screen "session" where "commandhere" is the command.
推荐答案
您是否尝试过 subprocess.call()
像这样:
Have you tried subprocess.call()
like this:
#!/usr/bin/python
import subprocess
subprocess.call(["screen", "-S", "session", "-X", "stuff", "'command here'`echo -ne '\015'`"])
另一个想法:最好创建一个bash
脚本来执行会话操作,并先让Python然后调用bash
脚本.
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.
这篇关于如何通过python将命令发送到运行屏幕(Ubuntu 12.04)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!