Windows批处理:获取刚刚启动进程的PID [英] Windows Batch scripting: Get PID of just started process

查看:2832
本文介绍了Windows批处理:获取刚刚启动进程的PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows批处理脚本有启动命令启动这一个新的过程中,你问。
现在的问题是:是否有可能得到我刚开始进程的PID

In Windows batch scripting there is "start" command which starts a new process you ask for. The question is: Is it possible to get PID of the process I just started ?

感谢。

推荐答案

您可以在批处理但不能直接每说。您需要为解析tasklist.exe或使用了Wmic.exe的输出。这都需要你知道你刚开始这当然你会的。

You can in batch but not directly per say. You need to either parse the output of tasklist.exe or use wmic.exe. Both require you to know what you just started which of course you will.

使用tasklist.exe:

Using tasklist.exe:

for /F "TOKENS=1,2,*" %a in ('tasklist /FI "IMAGENAME eq powershell.exe"') do set MyPID=%b
echo %MyPID%

要在批处理脚本中使用这双了百分比符号。

To use this in a batch script double up the percent signs.

使用了Wmic.exe:

Using wmic.exe:

for /f "TOKENS=1" %a in ('wmic PROCESS where "Name='powershell.exe'" get ProcessID ^| findstr [0-9]') do set MyPID=%a
echo  %MyPID%

这篇关于Windows批处理:获取刚刚启动进程的PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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