import subprocess
while True:
subprocess.call(input("> "), shell=True)
比方说,当我运行
adb shell settings get system volume_music_speaker
时,如何获取控制台输出并存储它,也就是说,它是最大音量,因此返回值为14。我已经尝试过
while True:
a = subprocess.call(input("> "), shell=True)
print(a)
但我总是得到 0。谢谢。
https://docs.python.org/3/library/subprocess.html#subprocess.PIPE
with subprocess.Popen(input("> "),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
) as your_process:
output, err = your_process.communicate()