Start-Transcript不记录子功能错误

时间:2016-08-10 10:49:12

标签: powershell

大家好我无法记录从主函数调用的其他函数中的错误或内容

cls
function one
{
   $logFile = "mypath\errorlog.log"
   Start-Transcript -path $logFile -Append | Out-Null
  try
 {
    two
 }
catch
{

}
finally
{
    Stop-Transcript
}
}

function two
{
  $arguments =  @("`"$myfile`"", "/s:`"$logPath`"")
  Start-Process -FilePath myexepath -ArgumentList $arguments -wait

 // when ever there are errors or some thing that is getting logeed in to $logPath that is not getting writing in to my Transcript
}

有人可以帮助我

1 个答案:

答案 0 :(得分:2)

你正在捕捉由2抛出的错误。另外,为什么你最后调用Stop-Transcript。看看这个Get-Help about_Try_Catch_Finally

Clear-Host
function one {
    $logFile = "mypath\errorlog.log"
    Start-Transcript -Path $logFile -Append | Out-Null
    try {
        two
    }
    catch {
        Write-Error $_
    }
    Stop-Transcript
}

function two {
    $arguments =  @("`"$myfile`"", "/s:`"$logPath`"")
    Start-Process -FilePath myexepath -ArgumentList $arguments -wait

    # when ever there are errors or some thing that is getting logeed in to $logPath that is not getting writing in to my Transcript
}
相关问题