ojhawkins
ojhawkins

Reputation: 3278

cURL output to file

Is it possible to direct this output from cURL into a file?

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1354  100  1354    0     0  17358      0 --:--:-- --:--:-- --:--:-- 17358
100 67081  100 67081    0     0  68171      0 --:--:-- --:--:-- --:--:-- 4031k

I cannot find anything in --help that would indicate you can. -o just done the response from what I can tell.

I am just wanting to know if the request succeded and how long it took.

Upvotes: 10

Views: 47750

Answers (2)

Pedro Lobito
Pedro Lobito

Reputation: 98921

This is what you need:

curl -o gettext.html http://www.gnu.org/software/gettext/manual/gettext.html 2> details.txt

The above will save the url to gettext.html and curl details to details.txt.

Upvotes: 8

MC ND
MC ND

Reputation: 70923

This output is sent to stderr. So, to get it all you need is redirect stream 2 (stderr) to a file as

curl -o responseFile.html http://www.somewhere.com 2> informationFile.txt

But, as your capture shows, times are not always included.

The better option to know if the request succeded and how long it took is to ask curl to output some internal variables. This is done with the -w switch. So, your command should look as

curl -o responseFile.html http://www.somewhere.com -w "%{response_code};%{time_total}" > dataFile.txt 2> informationFile.txt

That way, the response will go to responseFile.html (or whatever you need), the progress information (stderr or stream 2) will go to informationFile.txt and the required request response code and time information will go to dataFile.txt

Upvotes: 18

Related Questions