How can I call an external command in Python?

Learn how to harness Python’s power by triggering external processes and programs, and capture or routing the resulting output.

By David Blaikie
September 6, 2016
Screenshot from "Executing an external command in Python" Screenshot from "Executing an external command in Python"

Python is characterized as a “glue language” allowing programmers to combine many different systems, data, and programs. Expert engineer and trainer David Blaikie will teach you how to harness Python’s true power by executing external processes and programs. Learn how to call an external command to capture its output, or route the output to the STDOUT data stream. David also teaches you how to issue the command directly to the shell, addressing the associated security concerns. Novice Python software developers with a basic understanding of OS processes will find this tutorial an invaluable addition to their skill set.

Click here to access our Python Learning Path and get more in-depth training.

Learn faster. Dig deeper. See farther.

Join the O'Reilly online learning platform. Get a free trial today and find answers on the fly, or master something new and useful.

Learn more

David Blaikie is a New York City-based engineer and trainer. He has taught Python, Advanced Python, Perl, and Advanced Perl at New York University’s School of Professional Studies, and has conducted corporate Python training for companies such as Google, Cisco, and Bloomberg, as well as for the U.S. Navy. David has been a release engineer at Google and a software developer for AppNexus, Conde Nast, and several startups. He is also the author of the bestselling O’Reilly book “Python Beyond the Basics: Object-Oriented Programming”. David’s contact information can be found at

Post topics: Open Source
Post tags: Questions