Advantages of subprocess over os.system

First of all, you are cutting out the middleman; subprocess.call by default avoids spawning a shell that examines your command, and directly spawns the requested process. This is important because, besides the efficiency side of the matter, you don’t have much control over the default shell behavior, and it actually typically works against you regarding … Read more

Python: How to get stdout after running os.system? [duplicate]

If all you need is the stdout output, then take a look at subprocess.check_output(): import subprocess batcmd=”dir” result = subprocess.check_output(batcmd, shell=True) Because you were using os.system(), you’d have to set shell=True to get the same behaviour. You do want to heed the security concerns about passing untrusted arguments to your shell. If you need to … Read more

tech