Is there a functional difference between the following two methods?
os.system("echo $HOME")
subprocess.call("echo $HOME")
This is a similar question to this one, but that question really focuses more on subprocess.Popen()
.
Is there a functional difference between the following two methods?
os.system("echo $HOME")
subprocess.call("echo $HOME")
This is a similar question to this one, but that question really focuses more on subprocess.Popen()
.
If you're running python (cpython) on windows the <built-in function system>
os.system will execute under the curtains _wsystem while if you're using a non-windows os, it'll use system.
While subprocess.call will use CreateProcess on windows and _posixsubprocess.fork_exec in posix-based operating-systems.
The above points should answer your questions about the main differences (structurally)... That said, I'd suggest you follow the most important advice from the os.system docs, which is:
The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.