0
我试图执行一个sript运行exe文件,获取输出,通过输出搜索,然后如果真做soemthing:POWERSHELL:管道exe文件输出到可变
$output = cmd /c file.exe additionalvariables --batch |
write-host |
where-object($_ -eq "Finished with Success") #finished with success does not work
if (-eq "Finished with Success") # I need to perform a check
{
"Command executed"
$tcp.Dispose()
Exit 0
}
else
{
"There is an issue with file.exe additionalvariables command"
EXIT 1
$tcp.Dispose()
}
所以成品成功在第1行不起作用,你知道如何检查陈述吗? if (-eq "Finished with Success")
。
什么是$ LASTEXITCODE的.exe文件完成后的价值? – lit
输出结果如何?举个例子 –
'where-object($ _ -eq“Finished with Success”)'应该是'where-object {$ _ -eq“Finished with Success”}'''write-host' should not be used as you正在将数据发送到另一个流。只要删除管道的那一部分,然后再试一次。 – Matt