我想写一个启动子进程的python脚本,并写入子进程标准输入。对输出进行一些测试,然后将更多命令写入标准输入。写入标准输入,访问被拒绝
我曾尝试:
def get_band():
print "band"
p = subprocess.Popen(["/path/to/program","-c","-"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
ran_stdout = p.communicate(input='show status')[0]
print(ran_stdout)
然而print语句给出:
Unable to connect at 127.0.0.1, Connection refused.
我在想,如果我这样做对吗?这里是关于我试图运行的过程的文档。我想用最后一个选项。
Running the tool from the Linux shell allows additional options, depending on the options given to the command. The options are as follows:
-h Displays help about the command
-c <Filename> Instead of taking typed commands interactively from a user the commands are read from the named file, i.e. in batch mode. When all commands are processed the CLI session ends automatically.
-c - As above but reads command from Linux stdin. This allows commands to be ‘piped’ to the program.
消息是否可以由子进程生成? – Bogdacutu 2013-04-09 16:15:03
是的,谢谢你,我想知道为什么会这样以及如何获得许可?如果我使用这些参数从终端运行进程,它运行良好。 – Paul 2013-04-09 16:19:33