看板 Python 關於我們 聯絡資訊
※ 引述《fordpines (阿福)》之銘言:
yeh6: echo <password> | sudo -S <command> , 只是密碼明文很好笑 11/05 09:56
針對這部份講一下, 主要有幾個解法 1. 用 getpass 模組在 runtime 獲得密碼 import getpass password = getpass.getpass('輸入密碼: ') Popen(f'echo {password} | sudo -S ...', shell=True) 2. 用 pexpect https://github.com/pexpect/pexpect 這個模組類似 Unix 的 expect 工具 可以讓你在程式裡指定遇到某個 prompt 的時候自動輸入資訊 基本上就是用在這個用途, 會比前面的 echo 解法更好 搭配 getpass 也就不用直接把密碼寫在程式裡了 3. 直接叫 subprocess 讓你輸入 用 Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) 就可以在 terminal 看到子程式的 prompt 和直接輸入回去 -- 作者 Linux (Windows) 看板 C_and_CPP 標題 [問題] 如何確認是否 free 對記憶體 時間 Fri Nov 2 00:14:03 2012
akasan:valgrind, 但 windowns 版的沒試過XD 11/02 00:43
akasan:linux 上那真的是不二選擇了 11/02 00:44
Linux:我是用 Windows ....>"< 11/02 00:45
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.161.94.175 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1509863380.A.F38.html
ssdoz2sk: 簽名檔 XDDDD 11/06 00:55