如何使用 If 语句检查子流程的输出?

How can I check the output of a subprocess using an If-statement?

我已经尝试使用 os.system、startswith 等和各种其他子进程函数(check_output、运行、调用...),但出现错误 TypeError: argument of type 'CompletedProcess' is not iterable 第 4 行

这是我的代码:

import subprocess

version = subprocess.run("wmic get os version")
if "10.0.22000" in version:
    print("You are running version 10.0.22000")
else:
    print("You are not running version 10.0.22000")```

您需要将 "wmic get os version" 文本转换为 "wmic os get version",然后将结果转换为字符串:

import subprocess

version = subprocess.run("wmic os get version")

if "10.0.22000" in str(version):
    print("You are running version 10.0.22000")
else:
    print("You are not running version 10.0.22000")