简体   繁体   中英

How to load a URL only if it exists in a batch file using curl for windows?

I am trying to shutdown a service running running locally by using URL like 'localhost:3502/shutdown' using curl.

I give curl 'localhost:3502/shutdown'. But I need to do this only if the service is still running. Else I should not.

I wanna do it in a batch file for windows.

Any help/suggestions?

netstat -p tcp -n -a | findstr /b /r /c:"  TCP[ ]*[0-9.]*:3502 " >nul && (
     curl http://localhost:3502/shutdown
)

I am not sure how you want to determine if the service is running. Maybe this can work. This code checks for existence of the listening port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM