How to run an external script in Python

 

Python offers a subprocess module for you to run external script, which is more flexible than its os.system() function. It provides more powerful facilities for spawning new processes and retrieving their results.

For instance,

import subprocess

subprocess.run(["ls", "-l"])

or for versions before Python 3.5, use the following:

import subprocess

subprocess.call(["ls", "-l"])

Comments

Popular posts from this blog

How to create a memory puzzle game with Python and Pygame (#005)

How to write a slide puzzle game with Python and Pygame (2020 tutorial)

Introduction to multitasking with Python #003 gevent (2020 tutorial)