如何获得“ wmic过程调用创建”的输出? [英] How to get the output of "wmic process call create"

查看:98
本文介绍了如何获得“ wmic过程调用创建”的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取 wmic流程调用create 的输出,因此我可以获取以下内容的 ProcessId 新创建的过程。如果我只是运行:

I'm trying to get the output of wmic process call create so I can get the ProcessId of the newly created process. If I just run:

wmic process call create "notepad.exe a.txt","d:\"

工作正常(打开文件 a.txt 文件夹 d:\ 下的 notepad )。现在,如果我尝试:

It works just fine (it opens the file a.txt under folder d:\ with notepad). Now, if I try:

for /f "usebackq delims==; tokens=1,2" %i in (`wmic process call create "notepad.exe a.txt","d:\"^|findstr ProcessId`) do @echo pid = %j

没有,并且向我显示错误:

It doesn't, and shows me the error:


格式化错误。
Sugerencia:<lista_parámetros> =<parámetro> [,<lista_parámetros>]。

Formato incorrecto. Sugerencia: <lista_parámetros> = <parámetro> [, <lista_parámetros>].

我真的不知道这里发生了什么,有人可以向我解释一下还是

I don't really know what's going on here, can anyone explain this to me or if this is possible at all?

注意:其他命令可以正常使用。例如,如果我运行:

NOTE: Other commands work fine. For instance, if I run:

for /f "usebackq" %i in (`wmic process where "executablepath like '%%notepad.exe'" get ProcessId /value^|findstr ProcessId`) do @echo OUTPUT: %i

给出预期的输出,在这种情况下为:

It gives the expected output, which in this case is:


输出:ProcessId = 2084

OUTPUT: ProcessId=2084

谢谢!

推荐答案

我刚刚找到了解决方法。由于该命令仅在命令提示符下直接起作用,因此我决定使用 cmd / c ... ,如下所示:

I just found how can it be done. Due to the command was working only directly in the command prompt I decided to use cmd /c "...", it's as follows:

for /f "usebackq delims==; tokens=1,2" %i in (`cmd /c "wmic process call create 'notepad.exe a.txt','d:\'"^|findstr ProcessId`) do @echo pid = %j

现在唯一的事情是 PID 需要缩小空间,但要注意其他一些事情。很抱歉给您带来不便。

Now the only thing is that the PID needs to be trimed out of spaces, but that something else. Sorry for the inconvinience.

这篇关于如何获得“ wmic过程调用创建”的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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