简体   繁体   English

taskkill 不工作:它说没有匹配的进程在运行

[英]taskkill not working: it says there are no matching process running

I have 4 batch files.我有 4 个批处理文件。 master.bat starts all the other 3 batch files. master.bat 启动所有其他 3 个批处理文件。

master.bat

@ECHO OFF
TITLE "MasterBatch"
start "mainJS" "mainJS.bat"
timeout /t 1
start "firefoxBatch" "firefoxStart.bat"
timeout /t 1

start "browserCheckBatch" "browserCheck.bat"
timeout /t 1
ECHO "4"

mainJS.bat file starts the main.js file which is node.js file mainJS.bat 文件启动 main.js 文件,即 node.js 文件

mainJS.bat

@ECHO OFF

node main.js

browserCheck.bat file terminates all the other batchfiles when firefox is terminated. browserCheck.bat 文件在 firefox 终止时终止所有其他批处理文件。

browserCheck.bat

@ECHO OFF

timeout /t 1

:LOOP
tasklist | find /i "firefox.exe" >nul 2>&1
IF errorlevel 1 (
    GOTO CONTINUE
)   ELSE (
    ECHO firefox still running
    timeout /T 5 /Nobreak
    GOTO LOOP
)

:CONTINUE
ECHO firefox closed

taskkill /F /FI "WINDOWTITLE eq  mainJS"
ECHO %mainJSTitle%
taskkill /F /FI "WINDOWTITLE eq  MasterBatch"
taskkill /F /FI "WINDOWTITLE eq  firefoxBatch"

But the problem is browsercheck.bat doesn't terminate mainJS batchfile.但问题是 browsercheck.bat 不会终止 mainJS 批处理文件。 I've looked into the problem and the windows automatically renames my mainJS batchfile window title into mainJS - mainJS.bat and this seems to make it impossible for my browsercheck.bat to close the mainJS.bat file.我调查了这个问题,windows 自动将我的 mainJS 批处理文件 window 标题重命名为 mainJS - mainJS.bat,这似乎使我的 browsercheck.bat 无法关闭 mainJS.bat 文件。 It doesn't happen to other batch files.其他批处理文件不会发生这种情况。 What should I do?我应该怎么办?

If we start a.cmd or.bat file without a Title, it is difficult to distinguish its function如果我们启动一个没有Title的.cmd或者.bat文件,很难区分它的function

在此处输入图像描述

We are encouraged to add a Title but that may then sometimes be varied by the calling method我们鼓励添加标题,但有时可能会因调用方法而异

在此处输入图像描述

To ensure a.bat or.CMD will itself report the same Title each time确保 a.bat or.CMD 本身每次都会报告相同的标题在此处输入图像描述

then get into the habit of using a first line like然后养成使用第一行的习惯

@ECHO OFF & Title MainJS

Generally avoid a "Long Phrase With Spaces" it easier if it is a short accurate Mnemonic.通常避免使用“带空格的长短语”,如果它是简短而准确的助记符,则更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM