import subprocess output = subprocess.Popen(['ls', '-l', '/home'], stdout=subprocess.PIPE) stdout, stderr = output.communicate() print(stdout.decode())
import subprocess output = subprocess.Popen(['python', 'script.py', 'arg1', 'arg2'], stdout=subprocess.PIPE) stdout, stderr = output.communicate() print(stdout.decode())
import subprocess input_data = b'This is some test data' output = subprocess.Popen(['wc', '-c'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = output.communicate(input=input_data) print(stdout.decode())This example runs the "wc -c" command and passes some input data to it. The output is the number of bytes in the input. The package library for Python subprocess Popen is part of the standard library, it does not require any external installation or setup.