Unable to store terminal output of subprocess with python -
my code has 2 potential outcomes in terminal: can't connect rfcomm socket: permission denied
, can't connect rfcomm socket: host down
. need store either result string in variable, i've tried has failed. code thought it:
from subprocess import check_output out = check_output(["sudo", "rfcomm", "connect", "0", "aa:bb:cc:dd:ee:ff", "10"]) print "output: %s" % out
instead nothing:
user:~/home $./foo.py can't connect rfcomm socket: permission denied output:
another attempt:
proc = subprocess.popen(["sudo rfcom connect 0 aa:bb:cc:dd:ee:ff 10"], stdout=subprocess.pipe, shell=true) (out, err) = proc.communicate() print "output: %s" % out, err
this @ least gives me when print. unfortunately it's "none" telling me there no error , not actual output:
user:~/home $./foo.py can't connect rfcomm socket: permission denied output: none
i've tried this this this this , couple others. i'm sure i'm missing piece of critical knowledge somewhere. pointers!
rfcomm
apparently writing output standard error, yet capturing standard output. capture both, include stderr=subprocess.stdout
in call check_output
:
subprocess.check_output(["sudo", "rfcomm", "connect", "0", "aa:bb:cc:dd:ee:ff", "10"], stderr=subprocess.stdout)
Comments
Post a Comment