我想在 Python 中调用多个命令。我在 Windows 上安装了腻子。
ssh 到 Linux 机器
ssh_command_string: plink -i yourppk.ppk ec2-user@instanceIp
从该机器调用将生成文件的命令
export_project_command_string: ./AppManage -export -out /opt/notme-Facebook.xml -app "Silver Fabric/notme-FacebookPostsExtraction0118" -user username-pw password -domain ion
下载这个文件
download_command_string: pscp -scp -i yourppk.ppk ec2-user@instanceIp:/opt/notme-Facebook.xml d:\
这些命令在我一一测试时是可以的,但我不知道如何在 Python 中一次调用它们。
我尝试了以下代码,但没有运气:
LINE_BUFFERED = 1
#NOTE: the first argument is a list
p = Popen(['cat'], shell = True, bufsize=LINE_BUFFERED, stdin=PIPE, stdout = PIPE, stderr = PIPE)
for cmd in [ssh_command_string, cd_command_string, export_project_command_string, download_command_string]:
time.sleep(1) # a delay to see that the commands appear one by one
p.stdin.write(cmd)
p.stdin.flush()
# even without .flush() it works as expected on my machine
p.stdin.close()