locked
How to get error messages from jobs RRS feed

  • Question

  • Hi All. 

    Consider the below example. 

    It fails due to the file that we are trying to zip does not exists.

    Calls to processes external to the powershell context that fails will not get caught by a try/catch so we need to test the $lastexitCode and use "throw" 

    Thats fine and it works. 

    But how do I extract the error message afterwards ? 

    I've tried with: 

    Write-Host ($job.ChildJobs[0].JobStateInfo.Reason.Message) -ForegroundColor blue

    But that only gives me what the stuff from the "throw"

    What I would like is to extract first part you get when you run the receive-job command: 

    zip warning: name not matched: C:\Temp\GG\CRSB\DealAttribute_pik.bcp

    zip error: Nothing to do! (try: zip -r C:\Temp\GG\CRSB\DealAttribute_bodilsen.zip . -i C:\Temp\GG\CRSB\DealAttribute_pik.bcp)

    How do I extract that part for the jobs that failed ? 

    Thursday, August 25, 2016 7:44 AM

Answers

  • You can't.  Write the zip output to a log file.


    \_(ツ)_/

    Actually, that's not necessarily true.

    It may be possible to use channel redirection to redirect the error channel and interpret the message:

    $res = zip ... 2>&1
    if ($res -like "zip error*")
    {
        #...
    }

    For more info on redirection, run this on the console:

    help about_redirection

    Cheers,
    Fred


    There's no place like 127.0.0.1


    • Edited by FWN Thursday, August 25, 2016 12:39 PM
    • Marked as answer by Bill_Stewart Tuesday, October 11, 2016 6:47 PM
    Thursday, August 25, 2016 12:39 PM

All replies

  • You can't.  Write the zip output to a log file.


    \_(ツ)_/

    Thursday, August 25, 2016 8:37 AM
  • Crap :)
    Thursday, August 25, 2016 8:44 AM
  • You can't.  Write the zip output to a log file.


    \_(ツ)_/

    Actually, that's not necessarily true.

    It may be possible to use channel redirection to redirect the error channel and interpret the message:

    $res = zip ... 2>&1
    if ($res -like "zip error*")
    {
        #...
    }

    For more info on redirection, run this on the console:

    help about_redirection

    Cheers,
    Fred


    There's no place like 127.0.0.1


    • Edited by FWN Thursday, August 25, 2016 12:39 PM
    • Marked as answer by Bill_Stewart Tuesday, October 11, 2016 6:47 PM
    Thursday, August 25, 2016 12:39 PM