开发者

How to retrieve information from curl using python subprocess

I'm using curl.exe on windows. But unfortunately I can't get back data from console.

python code looks like this:

tid = subprocess.Popen("C:/users/zero/Desktop/lm/curl.exe -i -H \"Cookie: login=" + userhash + "\" -F \"type=" + caid + "\" -F \"description=\" -F \"descr=" + cleaned + "\" -F \"filetype=2\" -F \"name=" + pavadinimas + "\" -F \"file=@" + namel + "\" -F \"tag=@" + nto + "\" http://www.isos.lt/upload.php")

I开发者_如何学C tried with process.returncode to retrieve the information, but I don't get correct info. I can see that info in cmd but I don't know how to get it. Maybe it's possible to get that info with stdout=subprocess.PIPE, process.communicate()?

EDIT:

This command posted by sukhbir helped. Thanks.

p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]

Where command is your command.


Using curl via subprocess is the hard way. Spare yourself the trouble and use urllib or pycurl.

[update]

Currently, the requests library is the best option for this kind of thing.


p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]

Where command is your command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜