How to close a .bat file with another .bat file

1

I have a .bat file running this code:

cd C:\Users\PC\Desktop\nginx-1.10.2\php
php-cgi -b 127.0.0.1:9000

But it needs to be open while it is being used. Is there any way to create another .bat to close this one? Thank you.

    
asked by anonymous 07.12.2016 / 12:42

2 answers

1

After much research, I finally figured out how to do it. This is the code for the .bat file that opens:

title startnginx.bat
cd C:\Users\PC\Desktop\nginx-1.10.2
start nginx.exe
cd C:\Users\PC\Desktop\nginx-1.10.2\php
php-cgi -b 127.0.0.1:9000

And this is the code to close:

taskkill /f /im nginx.exe
Taskkill /fi "windowtitle eq startnginx.bat"

Basically the .bat file that opens has to be assigned a title so that you can then search for the title in the .bat file that is to close.

Thanks to all who helped me.

    
07.12.2016 / 15:22
0

Add this to your bat file:

@Echo Off
title NomeDoFicheiro.bat

In the other bat file you are going to create enter this:

start "" NomeDoFicheiro.bat
ping -n 10 localhost >nul
taskkill /f /im cmd.exe /fi "windowtitle eq NomeDoFicheiro.bat"

I hope it helps.

    
07.12.2016 / 13:10