I have a start.bat
similar to the following:
start npx tailwindcss -i ./www/src/styles/main.css -o ./www/dist/styles/main.css --watch
start caddy run
It launches 2 new cmd prompts and starts processes within them (which both run indefinitely). Is there a way for this bat file to send a kill command to the cmds it spawned? Ideally I'd have a single command to kill all "child" processes which were created.
CodePudding user response:
set "wintitle=my process %time%"
start "%wintitle%" npx tailwindcss -i ./www/src/styles/main.css -o ./www/dist/styles/main.css --watch
start "%wintitle%" caddy run
....
taskkill /FI "WINDOWTITLE eq %wintitle%"
[untested] - should work in theory...
CodePudding user response:
A PowerShell solution, using the Start-Process
and Stop-Process
cmdlets:
$processes = & {
Start-Process -PassThru npx 'tailwindcss -i ./www/src/styles/main.css -o ./www/dist/styles/main.css --watch'
Start-Process -PassThru caddy run
}
# ...
# Stop (kill) all launched processes.
$processes | Stop-Process