从python控制shell stdin
我有一个自定义输入法,我有一个python模块与之通信。我正试图用它来控制shell,这样从本地stdout到远程设备的所有内容都会打印在远程设备上,从远程设备发送的所有内容都会进入本地stdin,这样远程设备就可以控制给程序的输入,就像在程序中有一个从python控制shell stdin,python,Python,我有一个自定义输入法,我有一个python模块与之通信。我正试图用它来控制shell,这样从本地stdout到远程设备的所有内容都会打印在远程设备上,从远程设备发送的所有内容都会进入本地stdin,这样远程设备就可以控制给程序的输入,就像在程序中有一个input函数一样,远程设备也可以回答这个问题(类似于ssh)。 我使用python子流程控制stdin和stdout: #! /usr/bin/python from subprocess import Popen, PIPE import th
input
函数一样,远程设备也可以回答这个问题(类似于ssh)。
我使用python子流程控制stdin和stdout:
#! /usr/bin/python
from subprocess import Popen, PIPE
import thread
from mymodule import remote_read, remote_write
def talk2proc(dap):
while True:
try:
remote_write(dap.stdout.read())
incmd = remote_read()
dap.stdin.write(incmd)
except Exception as e:
print (e)
break
while True:
cmd = remote_read()
if cmd != 'quit':
p = Popen(['bash', '-c', '"%s"'%cmd], stdout=PIPE, stdin=PIPE, stderr=PIPE)
thread.start_new_thread(talk2proc, (p,))
p.wait()
else:
break
但它不起作用,我该怎么办
p、 美国。
windows有什么不同吗?我有这个问题,我用它来处理STDIN
from subprocess import call
call(['some_app', 'param'], STDIN=open("a.txt", "rb"))
a、 文本
这是我在git包装中使用的,它将在
某些应用程序中出现预期的中断时以行方式输入数据,并且用户输入对Windows有差异。这一行在Windows中不起作用:
p = Popen(['bash', '-c', '"%s"'%cmd], stdout=PIPE, stdin=PIPE, stderr=PIPE)
因为'bash'
的等价物是'cmd.exe'
p = Popen(['bash', '-c', '"%s"'%cmd], stdout=PIPE, stdin=PIPE, stderr=PIPE)