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

Asked

Viewed 1,583 times

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’s being used. Is there any way to create another . bat to close that? Thank you.

  • Close or terminate his execution?

  • I think it’s close, for example like clicking on X to close.

  • Why close via script? Even if possible, you will spend the same (maybe higher) amount of clicks/time to use the new . bat.

2 answers

1

Add this to your bat file:

@Echo Off
title NomeDoFicheiro.bat

In the other bat file you 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.

  • Me when I add @Echo Off title Filename.bat The command you had before does not appear or give.

  • I’ll try to explain better, I have two files . bat, one is startnginx and the other stopnginx. startnginx is to start and stay open until the user doesn’t want it anymore, and stopnginx is what will close startnginx.

  • Then just create your stopnginx.bat file and enter the seguint scrpt: taskkill /F /IM startnginx.bat

  • I’ve tried and won’t close

1

After a lot of research, I finally figured out how to do it. This is the source of 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 in order to search for the title in the . bat file that is to close.

Thank you to everyone who helped me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.