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

Time:03-01

I have already tried using os.system, startswith, etc and various other subprocess functions (check_output, run, call, ...) but I get the error TypeError: argument of type 'CompletedProcess' is not iterable in line 4

Here is my code:

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")```

CodePudding user response:

You needed to switch your "wmic get os version" text to "wmic os get version" and then convert the result to string:

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")
  • Related