从python子进程获取adb命令的控制台输出

stszievb  于 2023-11-20  发布在  Python
关注(0)|答案(1)|浏览(162)
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分,谢谢

uqzxnwby

uqzxnwby1#

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()

字符串

相关问题