简体   繁体   English

Wmic进程在for循环中调用未启动cmd

[英]Wmic process call in for loop doesn't start the cmd

I am trying to retrieve the ProcessID of a Java app launched through a batch file. 我正在尝试检索通过批处理文件启动的Java应用程序的ProcessID。 The problem is that the application does not start. 问题是该应用程序无法启动。

My code: 我的代码:

set cmd=java -jar XXXXXXX.jar XXXXXX.yml
for /f "tokens=2 delims==; " %%a in (' wmic process call create "%cmd%" ^| find "ProcessId" ') do set PID=%%a
start cmd /k echo %pid%
PAUSE

Batch files are pretty picky with whitespace. 批处理文件对空格非常挑剔。

Change this: 更改此:

set cmd = java -jar XXXXXXX.jar XXXXXX.yml

To this: 对此:

set cmd=java -jar XXXXXXX.jar XXXXXX.yml

This works: 这有效:

set cmd=notepad

for /f "tokens=2 delims==; " %%a in (' wmic process call create "%cmd%" ^| find "ProcessId" ') do set PID=%%a

start cmd /k echo %pid%

PAUSE

There may be something wrong with your jar file or perhaps java is not on your PATH. 您的jar文件可能存在问题,或者PATH中没有java。 Try running your command directly at a command prompt to see if it works: 尝试直接在命令提示符处运行命令以查看其是否有效:

c:\>java -jar XXXXXXX.jar XXXXXX.yml

Also make sure that you use the full path to your jar file in your cmd otherwise the path will be relative to your system folder: 还要确保在cmd中使用jar文件的完整路径,否则该路径将相对于系统文件夹:

set cmd=java -jar c:\yourpath\XXXXXXX.jar XXXXXX.yml

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

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