【发布时间】:2014-04-05 15:41:52
【问题描述】:
我正在编写一个函数来执行 shell 命令并在批处理脚本中捕获其输出。
:runShellCmd
setlocal EnableDelayedExpansion
SET lf=-
FOR /F "delims=" %%i IN ('%~1') DO if "%out%" == "" (set out=%%i) else (set out=!out!%lf%%%i)
echo "Cmd output: %out%"
SET "funOut=%out%"
ENDLOCAL & IF "%~1" NEQ "" SET %~2=%out%
goto :EOF
我已经成功地传递了简单的命令并获得了输出。但是对于像
这样的电话CALL :runShellCmd "echo Jatin Kumar | find /c /i "jatin"" 失败并出现错误unexpected | character。
我知道我们需要在 for 中使用 ^ 转义 |,但如果我尝试在函数参数字符串中传递 ^|,它会将其更改为 ^^|,这又会引发错误。
我错过了什么吗?
【问题讨论】:
标签: windows batch-file escaping call pipe