How do I pipe or redirect the output of curl -v?

后端 未结 8 1785
挽巷
挽巷 2021-01-29 21:17

For some reason the output always gets printed to the terminal, regardless of whether I redirect it via 2> or > or |. Is there a way to get around this? Why is this happening?

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 22:03

    I found the same thing: curl by itself would print to STDOUT, but could not be piped into another program.

    At first, I thought I had solved it by using xargs to echo the output first:

    curl -s ...  | xargs -0 echo | ...
    

    But then, as pointed out in the comments, it also works without the xargs part, so -s (silent mode) is the key to preventing extraneous progress output to STDOUT:

    curl -s ...  | perl  -ne 'print $1 if /([^<]+)/'
    

    The above example grabs the simple content (containing no embedded tags) from the XML output of the curl statement.

提交回复
热议问题