只是想知道为什么我得到" |在这个时候出人意料。"运行以下内容时出现错误消息:
for /f "tokens=2 delims==; " %%a in (' (wmic process call create "%exec%","%workdir%") ^| find "test" ') do set test=%%a
但运行以下内容时没有错误:
(wmic process call create "%exec%","%workdir%") ^| find "test"
谢谢!
答案 0 :(得分:0)
解析后的命令中有更多字符escaped:
(wmic process call create "%exec%","%workdir%") | find "test"
rem need to escape: ↑ ↑ ↑ ↑
下一个命令应该有效 - 尽管在wmic
输出中找不到'test'字,可能是:
for /f "tokens=2 delims==; " %%a in (' ^(wmic process call create "%exec%"^,"%workdir%"^) ^| find "test" ') do set test=%%a
rem properly escaped: ↑ ↑ ↑ ↑
使用
进行测试(wmic process call create "cmd.exe","%temp%") | find "ProcessId"
然后,下一个命令将创建的cmd
的进程ID设置为变量test
:
for /f "tokens=2 delims==; " %%a in (' ^(wmic process call create "cmd.exe"^,"%temp%"^) ^| find "ProcessId" ') do set test=%%a