杀批处理文件,它的孩子被杀害过,在Windows这样的方式 [英] Kill batch file in such a way that its children are killed too, in Windows

查看:408
本文介绍了杀批处理文件,它的孩子被杀害过,在Windows这样的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开始一个 exe文件 CMD (包exe文件,所以我可以提供一些命令行选项​​)。问题是,只调用从CMD exe文件不会使包装完全透明:如果该.exe挂起,杀死CMD不会杀exe文件。我需要它来杀死exe文件了。我可以这样做,在平原的Windows(从XP上),不添加任何依赖关系?

I need to start an exe from a cmd (wrap the exe so I can supply some command-line options). The problem is that just calling the exe from the cmd does not make the wrapping completely transparent: if the .exe hangs, killing the cmd won't kill the exe. I need it to kill the exe too. Can I do that in plain Windows (from XP up), without adding any dependencies?

在bash,那么你有 EXEC 取代用提供的命令shell进程。这是非常方便的编写包装脚本,使包装过程完全透明。我知道的Windows缺少的execve()来做到这一点,但我只在父杀,其子女的部分感兴趣。

In Bash you have exec which replaces the shell process with the supplied command. This is handy for writing wrapper scripts, making the wrapping process completely transparent. I know Windows lacks execve() to make this possible, but I'm only interested in the parent-killing-its-children part.

澄清:我不是在寻找各种方法来杀exe文件,我想办法的的(开始)的exe文件,以便使用标准的方式杀死它(如Ctrl + C或。从任务管理器)的作品。例如,我可以创建一个 LNK 文件(Windows快捷方式),并得到这种行为,但我想从一个脚本(做一个,LNKS只能使用绝对路径工作我无法部署)。

CLARIFICATION: I'm not looking for ways to kill the exe, I am looking for ways to wrap (start) the exe so that killing it using standard ways (eg. Ctrl+C or from task manager) works. For instance, I could create a lnk file (Windows shortcut) and get this behavior, but I want to do it from a script (for one, lnks only work with absolute paths, I can't deploy that).

感谢。

推荐答案

TASKKILL ,可以用来匹配一定的标准。通过输入 TASKKILL /?你得到的手册,可以在如何使用公共属性来筛选阅读起来。我认为所有的孩子分享他们的名字一个共同的部分。你可以使用的taskkill到数学的名称使用通配符并关闭匹配所有的孩子这个名字。

Taskkill can be used to match certain criteria. By entering Taskkill/? you get the manual and can read up on how to filter using common properties. I assume that all your children share a common portion in their name. You could use taskkill to math the name with wildcards and close all children that matched that name.

编辑(从评论部分获取):
由于IInspectable指出,可以使用 / T杀死所有的子进程标记。

EDIT (taken from the comments section): As IInspectable points out you can kill all child processes using the /T flag.

编辑从一个批处理,您可以使用启动开始参考这里)平行exe文件启动到批处理并在该批次的中止。

EDIT starting from a batch you could use START (reference here) to launch the exe parallel to the batch and have your abort in the batch.

编辑我写了并测试这个小例子:

Edit i wrote and tested this mini example:

@echo off
echo starting %1
start %1
echo Any key to kill execution
pause >>  NUL
taskkill /IM %1 /t

这篇关于杀批处理文件,它的孩子被杀害过,在Windows这样的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆