Answers for "os.system get output"

3

python get output of command to variable

import subprocess as sp
output = sp.getoutput('whoami --version')
print (output)
Posted by: Guest on June-15-2020
1

capture output of os.system in python

Capture output of os.system in python
Using popen:

import os
os.popen('cat /etc/services').read()

OR

import subprocess
proc = subprocess.Popen(["cat", "/etc/services"], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
print "program output:", out
Posted by: Guest on October-13-2021

Code answers related to "os.system get output"

Python Answers by Framework

Browse Popular Code Answers by Language