python - Get stdout from curl using Popen -
this code not working expected:
cmd = subprocess.popen(["curl"], stdout = subprocess.pipe) (out,err) = cmd.communicate() print(out) print(err)
out
empty line , err
none
, instead output printed console.
i expecting output stored out variable, i'm using windows 7 , python 2.7.
how read output variable?
type curl
on command line , you'll error message because didn't supply required parameters. didn't in out
because curl
wrote error message stderr
. , didn't err
because didn't redirect pipe in popen
. try instead:
cmd = subprocess.popen(["curl"], stdout=subprocess.pipe, stderr=subprocess.pipe) out,err = cmd.communicate() print('out:', out) print('err:', err) print('returncode:', cmd.returncode)
Comments
Post a Comment