We can pass in an entire shell command (command name + arguments) as a single string using the run()
option shell=True
:
1 2 3 | from subprocess import run run( 'echo "Hello, world!"', shell=True ) |
This code has the same effect as run( [ 'echo', 'Hello, world!' ] )
.
Using shell=True
allows us to use the system's shell operator syntax like >
and |
. For example, on Linux or macOS, we can run:
1 2 3 4 | from subprocess import run run( 'curl https://example.com 2>/dev/null | grep iana', shell=True ) |