0

Hi all I am not able to log the errors or the content from the other function which are getting called from main function

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
}

So can some one help me

Nithya
  • 47
  • 2
  • 14
  • I think the pb is not related to where are the transcripts instruction but to the fact you have to redirect output from the process, see http://stackoverflow.com/questions/8761888/powershell-capturing-standard-out-and-error-with-start-process Why use start-process instead of `&myexepath` ? – PlageMan Aug 10 '16 at 13:36

1 Answers1

1

You are catching the error that is thrown by 2. Also, why are you calling Stop-Transcript inside of finally. Look at this 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
}
Shawn Esterman
  • 2,292
  • 1
  • 10
  • 15