Stop batch file with another batch file?
I have a batch file that launches a new batch file at a new cmd prompt using the following command:
C:\Windows\System32\cmd.exe /c "start mybatch.bat"
The process mybatch.bat
continues to run until someone stops it. When we close this batch file with the Ctrl+ signal C, it performs a coverage data collection operation and then exits. After starting the file, mybatch
I am doing another process in the parent batch file and then I want to stop the file mybatch
.
I tried to use taskkill
to close the process using the command in the parent batch file:
taskkill /fi "windowtitle eq c:\Windows\SYSTEM32\cmd.exe - mybatch.bat"
The problem is that it stops the batch file, preventing it from starting the coverage process that would have happened if I had used the Ctrl+ Cmanually. Any thoughts on how I could achieve stopping mybatch file using the parent batch file?
Everything is done using a batch file. Any help is appreciated.
My main batch file looks something like this:
start mybatch.bat
REM do something like copying files, running tests, etc
taskkill /fi "windowtitle eq c:\Windows\SYSTEM32\cmd.exe - mybatch.bat"
In the above code instead of taskkill
what if I want to do Ctrl+ Cat the command line with windowtitle "c: \ Windows \ SYSTEM32 \ cmd.exe - mybatch.bat" using the main batch file. Is it possible?
source to share
There is no such thing as "please do something" - a message to a batch file. You will have to imitate him, for example, as follows:
REM mybatch.bat
:loop
REM do useful things
if not exist "c:\triggerfile.tmp" goto :loop
del "c:\triggerfile.tmp"
REM do "postprocessing"
exit
In your main bat file, instead of taskkill
justecho x>"c:\triggerfile.tmp"
source to share
test.bat
@echo off
title mybatchfile
echo ...do something
testkill.bat
Taskkill /FI "WINDOWTITLE eq mybatchfile"
testkill.bat will kill test.bat
But you have already tried this.
UPDATED
This cannot be done to stop a party from another party. But you can run the package as a service to set the process name, then you can define what to do on startup and shutdown. This service can kill from a batch file.
see my answer here
source to share
I used the SendKey.exe utility (Delphi console application), which emulates keystrokes but is part of the internal application. I tried the following command and it worked fine. The app uses Win32 keybd_event calls.
SendKey.exe -wn "TestLoop.bat" -ks "{CTRL + C} Y {ENTER}"
You can use NirCmd to send keystrokes, which I think should work.
source to share