0

I'm trying to use the vbs script to curl an url then get the script errorlevel. but always got 6 returned.

this can get the right errorlevel

C:\Users\lo>curl -Iks https://www.baidu.com | findstr /i 200
HTTP/1.1 200 OK
C:\Users\lo>echo %errorlevel%
0
C:\Users\lo>curl -Iks https://www.baidu.com | findstr /i hahaha
C:\Users\lo>echo %errorlevel%
1

below is vbs script

Set shell = CreateObject("WScript.Shell")
rc1 = shell.run("curl -Iks https://www.baidu.com | find /i 200", 0, true)
WScript.echo(rc1)

rc2 = shell.run("curl -Iks https://www.baidu.com | find /i hahaha", 0, true)
WScript.echo(rc2)

BR//lo

  • CMD is the program that does rediection so it must be running. –  Jun 03 '20 at 12:49
  • using comspec /c can got the right errorlevel code. rc2 = shell.run("%comspec% /c curl -Iks https://www.baidu.com | find /i hahaha", 0, true) – lothario wu Jun 04 '20 at 03:19

0 Answers0