我想从批处理文件调用PowerShell脚本。powershell批处理文件结果作为变量
我有以下
for /F "usebackq delims=" %%a in (
'PowerShell.exe -ExecutionPolicy ByPass -Command "(@(Select-String %QUERY% %FILE% -Context 0, 1 | % {$_.Context.PostContext}))"'
) do set RESULT=%%a
echo %RESULT%
但%RESULT%
正在打印整个命令没有结果。
所有我想要做的是阅读文件为标志,然后返回下一行作为%RESULT%
我跑的命令行
PowerShell.exe -ExecutionPolicy ByPass -Command "& (Select-String FAILED e:\path\to\app.log -Context 0, 1 | % {$_.Context.PostContext})"
以下,并得到这个
& : The term ':generic/generic.k4.csv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & (Select-String FAILED e:\path\to\app.log -Context 0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:generic/generic.k4.csv:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
他还得用'^ |'来逃避管道。 – SomethingDark
@SomethingDark通常我会同意,但是当我运行该命令时,它正确执行而不会泄漏管道。 ¡\\ _(ツ)_ /¯ –
我一直在[斥责之前](http://stackoverflow.com/questions/35962454/35962630#comment59585741_35962630)暗示有人逃脱一个字符,并非严格要求的解析器,所以我不打算再次提出它,除非我确定没有它的代码将无法正常工作。 –