从python子进程中获取adb命令的返回值

问题描述 投票:0回答:1
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。谢谢。

python python-3.x terminal adb
1个回答
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()
© www.soinside.com 2019 - 2024. All rights reserved.