修改 .bat 文件以不仅启动并发进程,而且关闭它们
Modify .bat file to not only launch simultaneous processes, but also close them
我正在 windows 上开发一个简单的多人纸牌游戏。出于测试目的,我想生成客户端 4 次,每次都来自其自己的 CMD 提示符,以便我可以看到每个实例的标准输出。
我当前的 startclient.bat 文件是:
echo "starting 4 player clients"
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
pause
总共打开了 5 个 CMD 提示符和 4 个游戏客户端。
如果我关闭链接到游戏客户端的 CMD 提示,游戏客户端 (python) 也会关闭,这太棒了!
如果我关闭主 CMD 提示符 (startup.bat),其他 4 个 CMD 提示符不会关闭。
我如何修改我的 .bat 文件,以便在我关闭主 CMD 提示符时所有内容立即关闭?
我会让你玩 "Truth or Consequences" 但这对我有用。
taskkill /t /fi "windowtitle eq Player2*"
SUCCESS: Sent termination signal to process with PID 26904, child of PID 26364.
SUCCESS: Sent termination signal to process with PID 26364, child of PID 24012.
taskill /t /fi "imagename eq cmd.exe"
ERROR: The process with PID 23176 (child process of PID 24012) could not be terminated.
Reason: The process cannot terminate itself.
ERROR: The process with PID 24012 (child process of PID 7440) could not be terminated.
这款游戏是 A Foot 亲爱的 Watson。
我可以玩脏游戏和/F(强制)控制台从外部关闭,但由于您添加了暂停,然后只需在“按任意键”后关闭 4 个外壳,让第五个外壳自然而干净地自行关闭。一旦您对进程的运行感到满意,就可以删除超时,无论 shell 是否已经关闭。
您可以根据自己的需要调整以下内容
Title Master & Mode 26,10 & color 50
Start "Player1" %comspec% /K "Color 40 & Mode 30,10 & Pause"
Start "Player2" %comspec% /K "Color 20 & Mode 30,10 & Pause"
Start "Player3" %comspec% /K "Color 10 & Mode 30,10 & Pause"
Start "Player4" %comspec% /K "Color 60 & Mode 30,10 & Pause"
Pause
taskkill /t /fi "windowtitle eq Player1*"
taskkill /t /fi "windowtitle eq Player2*"
taskkill /t /fi "windowtitle eq Player3*"
taskkill /t /fi "windowtitle eq Player4*"
timeout 4
exit /b
我正在 windows 上开发一个简单的多人纸牌游戏。出于测试目的,我想生成客户端 4 次,每次都来自其自己的 CMD 提示符,以便我可以看到每个实例的标准输出。
我当前的 startclient.bat 文件是:
echo "starting 4 player clients"
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
start cmd /k ..\.venv\Scripts\python.exe player_main.py &
pause
总共打开了 5 个 CMD 提示符和 4 个游戏客户端。
如果我关闭链接到游戏客户端的 CMD 提示,游戏客户端 (python) 也会关闭,这太棒了!
如果我关闭主 CMD 提示符 (startup.bat),其他 4 个 CMD 提示符不会关闭。 我如何修改我的 .bat 文件,以便在我关闭主 CMD 提示符时所有内容立即关闭?
我会让你玩 "Truth or Consequences" 但这对我有用。
taskkill /t /fi "windowtitle eq Player2*"
SUCCESS: Sent termination signal to process with PID 26904, child of PID 26364.
SUCCESS: Sent termination signal to process with PID 26364, child of PID 24012.
taskill /t /fi "imagename eq cmd.exe"
ERROR: The process with PID 23176 (child process of PID 24012) could not be terminated.
Reason: The process cannot terminate itself.
ERROR: The process with PID 24012 (child process of PID 7440) could not be terminated.
这款游戏是 A Foot 亲爱的 Watson。
我可以玩脏游戏和/F(强制)控制台从外部关闭,但由于您添加了暂停,然后只需在“按任意键”后关闭 4 个外壳,让第五个外壳自然而干净地自行关闭。一旦您对进程的运行感到满意,就可以删除超时,无论 shell 是否已经关闭。
您可以根据自己的需要调整以下内容
Title Master & Mode 26,10 & color 50
Start "Player1" %comspec% /K "Color 40 & Mode 30,10 & Pause"
Start "Player2" %comspec% /K "Color 20 & Mode 30,10 & Pause"
Start "Player3" %comspec% /K "Color 10 & Mode 30,10 & Pause"
Start "Player4" %comspec% /K "Color 60 & Mode 30,10 & Pause"
Pause
taskkill /t /fi "windowtitle eq Player1*"
taskkill /t /fi "windowtitle eq Player2*"
taskkill /t /fi "windowtitle eq Player3*"
taskkill /t /fi "windowtitle eq Player4*"
timeout 4
exit /b