Week 14 • Monday

Block 132: subprocess: Running System Commands

Execute shell commands and capture output from Python.

Concepts

Code Examples

See exercise below.

Exercise

Run 'ls' or 'dir' from Python and print the output. Run 'ping' or 'nslookup' and capture stdout to a file.

Homework

What is the security risk of subprocess.run('command ' + user_input, shell=True)? How do you avoid it? Tuesday