在下面的脚本中我想捕获release.bat的exitcode,以便svn提交,如果它成功。问题是提交是在release.bat结束之前完成的(这是我公司' vb6客户端的构建批处理)。我试着睡觉这个程序,但我觉得编程很糟糕,脚本的持续时间并不总是一样的。那么有什么解决方案可以从脚本中捕获实际的exitcode吗?
$strRevisionNumber1 = [string]$null
$timestamp = get-date -f "yyyy-M-d-h-m-s"
$SvnLogPath= Get-Location
$logfile = "${SvnLogPath}svn_dotnet_update_${timestamp}.log"
new-item -type file $logfile | out-null
$lcllogfile = "C:\Users\dimser.DEVELVM\Desktop\BuildAutomationTrunks\dotnet\build\logs.xml"
$dotnettrnk = "C:\Users\dimser.DEVELVM\Desktop\BuildAutomationTrunks\dotnet"
$build = "C:\Users\dimser.DEVELVM\Desktop\BuildAutomationTrunks\dotnet\build\release.bat"
#########################################################################################################################
##############SCRIPT##############
# ISSUING SVN UPDATE TO EACH DIR"
$dotnettrnk | % {svn update $_ 2>&1 | ft -AutoSize -Wrap | Out-File -Append $logfile }
#SVN UPDATE VERSION TARGETS
Invoke-Expression "C:\Users\dimser.DEVELVM\Desktop\Scripts\reviseRevNumber.ps1"
# ISSUING SVN LOGS TO LOGS.XML
$dotnettrnk |% {svn log -l 1 -v --xml $_ 2>&1 | ft -AutoSize -Wrap | Out-File $lcllogfile }
# OPEN LOG FILE AFTER THE COMPLETION
notepad $logfile
notepad $lcllogfile
[xml]$xml = (get-content $lcllogfile)
#STORES THE REVISION NUMBER FOR THE COMMIT
$strRevisionNumber1 = $xml.log.logentry.revision
Write-Host $strRevisionNumber1
$LASTEXITCODE = 1
#CALL THE BUILD SCRIPT
cmd /c $build
Write-host $LASTEXITCODE
#CHECK IF BUILD WAS SUCCESSFUL
if($LASTEXITCODE -eq 0)
{
# ISSUING SVN COMMIT
$dotnettrnk | % {svn commit -m "Build: revision: $strRevisionNumber1" $_ 2>&1 | ft -AutoSize -Wrap | Out-File -Append $logfile }
}
答案 0 :(得分:0)
尝试使用Start-Process $build -Wait
代替cmd /c $build
。