我正在编写一个脚本来获取显示器的状态以查看它是否已开机,但是

问题描述 投票:0回答:1

我在“WHERE”方面遇到问题。我已经在命令提示符中写下了它,它工作得很好,但是使用 Popen 会生成 stderr 错误“无效动词。”。

        from subprocess import Popen, PIPE

        stdout, stderr = Popen([
            'wmic',
            'path',
            'win32_videocontroller',
            'WHERE "Name = \'Intel(R) UHD Graphics 630\'"',
            'GET',
            'Availability'
        ],
            stdout = PIPE,
            stderr = PIPE,
            text = True
        ).communicate()
python subprocess popen wmic
1个回答
0
投票
    from subprocess import Popen, PIPE

    stdout, stderr = Popen([
        'wmic',
        'path',
        'Win32_VideoController',
        'WHERE',
        'Name=\'Intel(R) UHD Graphics 630\'',
        'GET',
        '/VALUE'
    ],
        stdout = PIPE,
        stderr = PIPE,
        text = True
    ).communicate()
    if len(stderr):
        print(f'Error: "{stderr}"')
    else:
        stdout = '\r\n'.join([line.rstrip(' ') for line in stdout.split('\n\n')[1:] if len(line) and not line.endswith('=')])
        stdout += '\r\n'
© www.soinside.com 2019 - 2024. All rights reserved.