Check if another batch file is still running

2019-09-05 15:25发布

I want batch1.bat to check if batch2.bat is running. If batch2.bat is running, I want nothing to happen. If batch2.bat is NOT running, I want batch1.bat to kill the process process1.exe.

In other words, I want batch1.bat to start batch2.bat and wait for it to be closed. Once it is closed, I want process1.exeto be ended.

How would I write batch1.bat?

1条回答
Bombasti
2楼-- · 2019-09-05 16:02

Batch1.cmd

@echo off
  echo 1: starting
  echo 1: calling batch2

  cmd /c "batch2.cmd"

  echo 1: back to batch1
  echo 1: end batch1

  taskkill /im process1.exe /f >nul 2>nul

Batch2.cmd

@echo off
  echo 2: starting batch2
  echo 2: in batch2
  pause
  echo 2: leaving batch2
查看更多
登录 后发表回答