From the course: Using Python for Automation

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Executing terminal commands

Executing terminal commands - Python Tutorial

From the course: Using Python for Automation

Executing terminal commands

- [Instructor] Terminal and command prompt are powerful programs that provide command-line interfaces with the ability to manipulate the respective operating systems. These tools can accomplish anything the graphical interface can with just a few keystrokes in the command line. To give our scripts access to these tools, let's learn how to run terminal commands in Python. To demonstrate this concept, we'll be executing external Python scripts using commands from the command line. To begin, let's create a dummy Python script that prints "Hello World" to the console. Let's go ahead and save the script and call it example.py. Next, create a new file to house our automated terminal logic. I'll go ahead and save this file as script.py. To implement automating terminal commands with Python, we'll be using the subprocess library. Subprocess is a library that allows our Python script to interact with the command line interface or shell. The subprocess library contains many…

Contents