2

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 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.
1
  • 1
    "EDIT: SOLVED" is rude. Please post the actual answer. You are allowed to answer your own question so that others may learn. "EDIT: SOLVED" helps no one. Commented Dec 30, 2010 at 15:59

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for requests. I could not believe the insanity of setup required by urllib and pycurl. The requests site is right: it shouldn't be this way in Python.
1
p = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]

Where command is your command.

2 Comments

And yes, listen to Paulo's advice.
It's good that it works, but there are better alternatives available which will make it easy for you to handle all this. Check out the links as shown by Paulo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.