我正在尝试运行一个运行putty的脚本,并在创建的putty终端中运行一个命令。我已经能够使用Python子进程模块和check_call或Popen从我的脚本启动putty。但是,我对如何在子进程Putty终端中从我的脚本运行命令感到困惑。我需要能够在putty中运行这个命令,并在Putty终端上分析它的输出。谢谢你的帮助。
发布于 2016-07-29 00:55:40
您需要将stdin参数设置为PIPE,并使用Popen的communicate函数将数据发送到标准输入。
from subprocess import Popen, PIPE
p = Popen('/the/command', stdin=PIPE, stdout=PIPE, stderr=PIPE)
std_out, std_err = p.communicate('command to putty')也就是说,使用实现ssh协议(如paramiko)的python库可能比使用putty更容易。
https://stackoverflow.com/questions/38642382
复制相似问题