Reputation: 625
I am using os.popen() to call some argument. When I call the argument itself in terminal it works perfectly and I get the expected return object. But when I call it using the os.popen() I get
os._wrap_close object at 0x7f6ec0d3d1d0>
Code:
> command = "python -m json.tool \"" + path + video +"-something.json\"| grep \"ext\\\"\"
> result = os.popen(command)
> print(result)
I find it confusing to get different results, when it should be the same thing
Upvotes: 1
Views: 9471
Reputation: 141
This command opens a pipe to the command (stdout, with popen2/3/4 stdin, stderr) and returns an open file object and not the stdout of the command. (python docs)
So in order to get the result of your command you have to read the open file which can be done with result.read()
.
Here is a nice explanation on the different popen and their (basic) usage.
Upvotes: 6