我目前正在尝试创建一个批处理脚本,以查找给定机器上是否安装了程序,如果程序已将其输出到文件中。但是,当我尝试获取字符串时,出现“ |意外”错误。
wmic product get name > C:\Users\%USERNAME%\Desktop\programswmic.txt
for /F "tokens=*" %%A in ('type C:\Users\%USERNAME%\Desktop\programswmic.txt | findstr /m "iTunes"') do (set var=%%A)
echo %var% > C:\Users\%USERNAME%\Desktop\endingoutput.txt
脚本的输出如下:
C:\Users\Landon\Desktop>test.bat
C:\Users\Landon\Desktop>wmic product get name 1>C:\Users\Landon\Desktop\programswmic.txt
| was unexpected at this time.
C:\Users\Landon\Desktop>for /F "tokens=*" %A in ('type C:\Users\Landon\Desktop\programswmic.txt | findstr /m "iTunes"') do (set var=%A)
C:\Users\Landon\Desktop>
我该如何解决?
答案 0 :(得分:0)
您需要使用|
转义^
字符。
wmic product get name > C:\Users\%USERNAME%\Desktop\programswmic.txt
for /F "tokens=*" %%A in ('type C:\Users\%USERNAME%\Desktop\programswmic.txt^| findstr /m "iTunes"') do (set var=%%A)
echo %var% > C:\Users\%USERNAME%\Desktop\endingoutput.txt