簡體   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