我正在放置一个batch file,它执行以下操作:
通过使用START命令调用2个batch file打开Selenium集线器和节点,以便它们在自己的cmd窗口中打开。 我完全赞同我的stream程,直到5),closures包含集线器和节点的两个cmd窗口。
我知道你可以closures所有的“cmd.exe”进程,但似乎很多钝器。 有没有一种方法来识别或保持由我的批处理脚本打开的hub和node cmd窗口的句柄,以便我可以只closures这两个?
谢谢。
作为美妙的npocmaka答案的替代方案,如果您知道或可以设置已启动的seleniumium窗口的标题,可以使用此信息来检索并过滤具有这些标题的任务列表。
当输出到控制台是正确的,从taskkill线删除echo命令
@echo off rem Prepare environment setlocal enableextensions rem Configure list of window titles set titles="seleniumHUB" "seleniumNODE" rem For each title in title list for %%t in (%titles%) do ( rem Get the list of task with the indicated window title. rem The list is get from tasklist, in verbose mode and in csv format rem The last column in the list is the window title for /f "tokens=1,2 delims=," %%a in ( 'tasklist /fi "imagename eq cmd.exe" /v /fo csv ^| findstr /i /r /c:"%%~t[^,]*$"' ) do ( echo taskkill /pid %%~b ) ) rem Clean endlocal
尝试这样的事情:
@echo off for /f "tokens=2 delims=;= " %%a in ('wmic process call create "cmd.exe /c C:\selenium.bat"^,"c:\workdir" ^| find "ProcessId"') do ( set "cmd_pid=%%a" ) taskkill /PID %cmd_pid% /f
用wmic process call create "cmd.exe /c C:\selenium.bat"你可以启动一个进程并获得它的PID,当你杀死它时,你可以使用taskkill /PID %cmd_pid% /f