windows cURL 输出到文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21226980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cURL output to file
提问by ojhawkins
Is it possible to direct this output from cURL into a file?
是否可以将此输出从 cURL 定向到文件中?
% 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.
我找不到任何--help
表明你可以的东西。-o
刚刚完成了我所知道的回应。
I am just wanting to know if the request succeded and how long it took.
我只是想知道请求是否成功以及花了多长时间。
回答by MC ND
This output is sent to stderr. So, to get it all you need is redirect stream 2 (stderr) to a file as
此输出被发送到 stderr。因此,要获得它,您需要将流 2 (stderr) 重定向到一个文件作为
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 输出一些内部变量。这是通过-w
开关完成的。所以,你的命令应该看起来像
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
这样,响应将转到 responseFile.html(或您需要的任何内容),进度信息(stderr 或流 2)将转到 informationFile.txt,所需的请求响应代码和时间信息将转到 dataFile.txt
回答by CONvid19
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
.
以上将保存 urlgettext.html
和 curl 详细信息到details.txt
.