如何通过python将命令发送到运行屏幕(Ubuntu 12.04) [英] How to send command via python to running screen (Ubuntu 12.04)

查看:90
本文介绍了如何通过python将命令发送到运行屏幕(Ubuntu 12.04)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆