Look at the subprocess module in the standard library:
import subprocess subprocess.run(["ls", "-l"])
The advantage of
system is that it is more flexible (you can get the
stderr, the "real" status code, better error handling, etc...).
The official documentation recommends the
subprocess module over the alternative
subprocessmodule provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function [
The Replacing Older Functions with the subprocess Module section in the
subprocess documentation may have some helpful recipes.
For versions of Python before 3.5, use
import subprocess subprocess.call(["ls", "-l"])