繁体   English   中英

python子进程popen运行多个命令

[英]python subprocess popen run multiple command

我想在Python中调用多个命令。 我在Windows上安装了腻子。

  1. ssh到Linux机器

     ssh_command_string: plink -i yourppk.ppk ec2-user@instanceIp 
  2. 从该机器上调用一个命令,该命令将生成一个文件

     export_project_command_string: ./AppManage -export -out /opt/notme-Facebook.xml -app "Silver Fabric/notme-FacebookPostsExtraction0118" -user username-pw password -domain ion 
  3. 下载此文件

     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()

面料到服务器上执行重复/自动任务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM