【问题标题】:In Batch variable not printing在批处理变量中不打印
【发布时间】:2016-05-01 13:42:22
【问题描述】:

我正在编写一个批处理文件来杀死给定进程 ID 的所有依赖进程。我还没有完成我的代码。现在我的代码是

set cmd="wmic process where (ParentProcessId=4192) get ProcessId"
FOR /F %%i IN (' %cmd% ') DO ( 
SET X=%%i 
echo The process is %X%
)

“wmic process where (ParentProcessId=4192) get ProcessId”命令的输出是:

ProcessID
3516
<blank space>

批量设置 X=ProcessID,3516 和空格。 问题 1:对于上面的代码,它没有显示 X 的值(在 echo 中)。 问题 2:我想要那些 %%i 是整数

【问题讨论】:

标签: windows batch-file


【解决方案1】:

你可以试试这样的:

@echo off
set cmd="wmic process where (ProcessId=4192) get ParentProcessId"
Setlocal EnableDelayedExpansion
FOR /F "skip=1 delims=" %%i IN ('%cmd%') DO ( 
    SET X=%%i 
    echo The process is !X!
)
pause
echo The process is %X%
EndLocal
pause

为什么不使用Taskkill 命令和参数/T 来终止指定进程和由它启动的任何子进程?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-24
    • 2021-07-03
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    相关资源
    最近更新 更多