Windows/*n*x: Getting curl to output HTTP status code – Super User
Posted by jpluimers on 2017/10/24
The first trick works in Windowa and nx (thanks [WayBack] pvandenberk):
curl -s -o /dev/null -I -w "%{http_code}" http://www.example.org/
Inside a Windows batch file you need to escape the % to %% so you get this:
curl -s -o /dev/null -I -w "%%{http_code}" http://www.example.org/
The second is slick but only works on nx (thanks [WayBack] Heath Borders):
#creates a new file descriptor 3 that redirects to 1 (STDOUT)
exec 3>&1
# Run curl in a separate command, capturing output of -w "%{http_code}" into HTTP_STATUS
# and sending the content to this command's STDOUT with -o >(cat >&3)
HTTP_STATUS=$(curl -w "%{http_code}" -o >(cat >&3) 'http://example.com')
[WayBack] Getting curl to output HTTP status code? – Super User
–jeroen






Leave a comment