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 check if a string contains a substring in Python

How to use Python conditional expression?(Python Conditional Expression)

How to create a box pusher game with Python and Pygame Source Code (2020)