Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading