1

I wish to read an XML file hosted on web via my C++ program. I'm working on LINUX. I'm currently using popen to read.

FILE* remote = popen("curl 'my_url_to_xml', "r")
fread(buf, 1024, 1, remote);

It works and gives me the content in the url but then it has this extra matter dumped on screen even though I'm not printing anything. Also the entire operation takes ~3000 ms. This is too much for my use case.

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
0    71    0    71    0     0    309      0 --:--:-- --:--:-- --:--:--     0

Any way to fix this or an alternative to popen? I wish to avoid third party libraries like libcurl. Any native solution ?

EDIT -- OK I accept even non native solutions are accepted. My first concern is popen. If this dumping problem can be fixed, I'll go with popen itself.

2 Answers 2

2

Call curl with the silent switch: -s OR --silent

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

2 Comments

thanks. Can you give me an idea how to include it with popen?
@Abhishek you would just edit the call to curl shown in your code and add the switch: popen("curl --silent 'my_url_to_xml', "r")
1

I wish to avoid third party libraries like libcurl. Any native solution ?

No. C++ is not a "web language" and it has zero support for XML or HTTP built in. You need to use a library like libcurl. Or another programming language. Or reimplement one of those yourself.

Seriously, just use libcurl or similar and be done with it. Or even better, use Python. :)

Comments

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.