I\'m trying to make a system call in Python and store the output to a string that I can manipulate in the Python program.
#!/usr/bin/python import subprocess
In Python 3.7 a new keyword argument capture_output was introduced for subprocess.run. Enabling the short and simple:
capture_output
subprocess.run
import subprocess p = subprocess.run("echo 'hello world!'", capture_output=True, shell=True, encoding="utf8") assert p.stdout == 'hello world!\n'