简体   繁体   English

批处理脚本关闭所需的命令提示符窗口

[英]Batch script to close desired Command Prompt windows

First, I have a script that starts 4 java programs: 首先,我有一个启动4个Java程序的脚本:

@echo off
cd "C:\work\clientes\loremIpsum\loremIpsum\loremIpsum\target"
start "BROKER" java -jar loremIpsum-broker.jar

cd "C:\work\clientes\loremIpsum\loremIpsum\loremIpsum-virtual-devices-engine\target"
start "VIRTUAL-DEVICES-ENGINE" java -jar loremIpsum-virtual-devices-engine.jar

cd "C:\work\clientes\loremIpsum\loremIpsum\loremIpsum-websocket\target"
start "WEBSOCKET" java -jar loremIpsum-websocket.jar

cd "C:\work\clientes\loremIpsum\loremIpsum-loremIpsum\dandelion-workflow-engine\target"
start "WORKFLOW-ENGINE" java -jar loremIpsum-workflow-engine.jar
exit

I want to make a script that closes only these 4. I´ve tried with wmic: 我想制作一个仅关闭这4个脚本。我尝试过使用wmic:

@echo off
wmic process where "name like '%java%'" delete
exit

But I don't want it to close my other java aplications, only these 4 但是我不希望它关闭我的其他Java应用程序,只有这4个

The most likely unique and known commandline, would be its ending, eg -broker.jar . 最可能的唯一已知命令行是其结尾,例如-broker.jar So the wildcard, % should represent the beginning of the commandline, ie %-broker.jar , (doubled in a batch file %%-broker.jar ) . 因此,通配符%应该代表命令行的开始,即%-broker.jar (在批处理文件%%-broker.jar You would therefore use the following: 因此,您将使用以下内容:

WMIC Process Where "CommandLine Like '%%-broker.jar'" Call Terminate

I would suspect however that java.exe actually passes the initial command through a separate instance of cmd.exe , opening it in another window, which could be problematic, unless we knew what command it passed! 但是我会怀疑java.exe实际上是通过cmd.exe一个单独实例传递初始命令的,并在另一个窗口中打开它,这可能是有问题的, 除非我们知道它传递了什么命令!

If the java command actually opens in a new cmd.exe window, with the window title you've stipulated, BROKER , you should be able to terminate it using TaskKill . 如果java命令实际上在新的cmd.exe窗口中打开,并且具有您指定的窗口标题BROKER ,则应该可以使用TaskKill终止它。 Perhaps something like this: 也许是这样的:

TaskKill /F /FI "WindowTitle Eq BROKER" /T >Nul

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

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