【发布时间】:2019-03-12 05:15:57
【问题描述】:
我想从命令行运行脚本,并获取错误级别。 我使用这个批处理脚本。
set log=C:\Users\PowerShell\XML\Log.txt
set PS=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
set PS=%PS%\powershell.exe
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" C:\Users\XML.ps1 -i C:\Users\A2.txt -j C:\Users\Fb.xml
echo %ERRORLEVEL% > "%log%"
我试过这个脚本来获取自定义的errorlevel,如果找到,它将返回123,否则返回456。但它总是给我1。
$regex = [regex]$Pattern
$matching = $regex.Match($FBString)
if ($matching.Success) {
while ($matching.Success) {
"Match found: {0}" -f $matching.Value
Exit 123
$matching = $matching.NextMatch()
}
}
else {
"Not Found"
Exit 456
}
【问题讨论】:
标签: powershell batch-file exit-code errorlevel