Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on API hitting using system function which is shown below.
I am working with Qt in the Linux environment.

ret = system("curl -m 60 --header \"content-type:application/json\" --data @/root/request.json MYURL -o /root/response.json");

Here system returns only 0 or -1 but I want to catch curl error codes.
Example :
6 Couldn't resolve host. The given remote host was not resolved.
7 Failed to connect to host.
28 Operation timeout. The specified time-out period was reached according to the conditions.

etc..


So can you please help me how to read this error from system function.

What I have tried:

ret = system("curl -m 60 --header \"content-type:application/json\" --data @/root/request.json MYURL -o /root/response.json");
Posted
Updated 2-Jun-19 22:24pm

1 solution

You cannot do it from a call to system(3) - Linux manual page[^] . You need to send the curl output to a file and then read that when the command has completed.
 
Share this answer
 
Comments
Member 13740197 3-Jun-19 5:00am    
I have already sent the output to a file /root/response.json. But this file is empty when curl error is 6 and 28 case. But my requirement is to read this error numbers.
Richard MacCutchan 3-Jun-19 5:06am    
You need to redirect the error output (stderr) to a file. You can test this quite easily by running the full command in a terminal window.
Member 13740197 3-Jun-19 6:41am    
Thanks for the answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900