Executing command line programs from within python [duplicate]

The subprocess module is the preferred way of running other programs from Python — much more flexible and nicer to use than os.system.

import subprocess
#subprocess.check_output(['ls', '-l'])  # All that is technically needed...
print(subprocess.check_output(['ls', '-l']))

Leave a Comment