2016-08-10 58 views
0

大家好,我不能登錄錯誤或其他功能,都可以從main函數調用的內容啓動成績單不記錄子功能錯誤

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 
} 

所以能有人幫我

+0

我覺得PB是不相關的在哪裏成績單指令,但你必須從輸出的過程中重定向事實上,看到http://stackoverflow.com/questions/8761888/powershell-capturing-standard -out-and-error-with-start-process 爲什麼使用start-process而不是'&myexepath'? – PlageMan

回答

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 
}