[英]How to send data to the terminal with python
嘗試子過程手冊 。 您可以使用帶有子進程的選項,以與正在調用的進程的stdin,stdout和stderr一起使用。
from subprocess import Popen, PIPE, STDOUT
p = Popen(['ask', 'util', 'generate-lwa-tokens'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, universal_newlines=True)
# Storing the values that should be passed
values = ["client_id", "client_secret"]
# Interacting with the shell
output, err = p.communicate(input=f'{values[0]}\n{values[1]}\n')
# Displaying outputs
print(output)
嘗試此操作,如果有任何錯誤,請發表評論。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.