Search⌘ K
AI Features

Learning to Communicate with subprocess

Explore how to effectively use Python's subprocess module to open processes, wait for return codes, and communicate with child processes. This lesson shows you how to pass input and read output with the communicate method for process interaction.

We'll cover the following...

There are several ways to communicate with the process you have invoked. We’re just going to focus on how to use the subprocess module’s communicate method. Let’s take a look:

Python 3.5
import subprocess
args = ["du"]
process = subprocess.Popen(args,
stdout=subprocess.PIPE)
data = process.communicate()
print(data)

In this code example, we create an args variable to hold our ...