亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何向 Popen() 傳遞多個輸入參數?

如何向 Popen() 傳遞多個輸入參數?

千巷貓影 2023-06-27 17:24:04
我正在編寫一個為用戶安裝命令行界面的腳本。proc = Popen("sudo -S apt-get install vim".split(), stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)# Popen only accepts byte-arrays so you must encode the stringoutput = proc.communicate(password.encode())stdoutput = (output)[0].decode('utf-8')輸出:Installing Vim...|Reading package lists...Building dependency tree...Reading state information...The following additional packages will be installed:  vim-runtimeSuggested packages:  ctags vim-doc vim-scriptsThe following NEW packages will be installed:  vim vim-runtime0 upgraded, 2 newly installed, 0 to remove and 5 not upgraded.Need to get 7,111 kB of archives.After this operation, 34.6 MB of additional disk space will be used.Do you want to continue? [Y/n] Abort.如您所見,軟件包的安裝停止Do you want to continue?,并且由于某種原因,安裝被中止。我如何y在這個階段使用傳遞 a Popen()?我已經使用傳遞密碼communicate(),但沒有進行多次輸入。
查看完整描述

1 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

-y只需作為選項傳遞apt-get即可避免與它(進一步)交互的需要。


proc = Popen(["sudo", "-S", "apt-get", "-y", "install", "vim"], stdin=PIPE, stdout=PIPE, stderr=PIPE)

output, error = proc.communicate(password.encode())

stdoutput = output.decode('utf-8')


查看完整回答
反對 回復 2023-06-27
  • 1 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號