簡體   English   中英

織物-自動執行標准輸入

[英]fabric - automate stdin inputs

我知道,我想要更多!

我想知道如何在Fabric中執行以下操作:

def deploy():
   local('git pull origin dev')
   gitusername = "test"
   gitpwd = "testpassword"
   # here render credentials to stdin so that no need to type in in console

   local('python manage.py collectstatic')       
   confirm_type = "yes"
   # here render 'confirm_type' to stdin so that I dont have to type in console

   local('python manage.py migrate')
   local('/etc/init.d/nginx restart')

我想到了fabric.operations.prompt但我不需要提示。 我希望該結構從變量中讀取憑據,然后繼續進行而不會問我任何事情。

有任何想法嗎?

如fabric 文檔中所述 ,使用子進程通過stdin發送數據(“ 如何編寫python子進程stdin ”中使用的代碼):

from subprocess import Popen, PIPE, STDOUT
p = Popen(['python', 'manage.py', 'collectstatic'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
stdout_data = p.communicate(input='yes')[0]

如果要查看輸出,請除去stdout,stderr參數。

另外,在使用collectstatic的情況下,您可以僅指定--noinput參數,而無需使用管道。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM