Powershell/Psake/Stderr - tasks abort when programs output to stderr

375 views
Skip to first unread message

Jrax

unread,
May 7, 2012, 1:08:43 PM5/7/12
to psake...@googlegroups.com
Hi,

Trying to get started w/psake and I'm having problems calling programs that output to stderr.   I first noticed problems when working in ISE.   Did web search and discovered that PS shell and ISE has different behavoir.  Workaround was to redirect stderr to stdout or $null.

The workaround seems to work as expected for PS functions but not psake tasks.

Following is error message:

OutToStdErr.exe : Output To StdErr
At C:\projects\AutomatedBuilds\PSake\stderr\funcs.ps1:11 char:33
+     $results = .\OutToStdErr.exe <<<<  2>&1
    + CategoryInfo          : NotSpecified: (Output To StdErr:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Following is what I'm experiencing.

Functions

                            Shell                             ISE
                            Expected  |  Actual        Expected  | Actual   
Normal                  Pass         |  Pass           Fail           | Fail
SaveOutputToVar   Pass         |  Pass           Fail           | Fail
StderrToStdout       Pass         | Pass            Pass        | Pass       
StderrToNull           Pass         | Pass            Pass        | Pass       

PSake Tasks

                            Shell                             ISE
                            Expected  |  Actual        Expected  | Actual   
Normal                  Pass         |  Pass           Fail           | Fail
SaveOutputToVar   Pass         |  Pass           Fail           | Fail
StderrToStdout       Pass         | Fail             Pass        | Fail             
StderrToNull           Pass         | Fail             Pass        | Fail             

The above table shows that the shell fails when output is redirected and nothing seems to work when in the ISE.

Hope the above makes sense.

Thanx for any help

Ps - test scripts attached.

John A.








default.ps1
funcs.ps1

James Kovacs

unread,
May 8, 2012, 1:58:35 PM5/8/12
to psake...@googlegroups.com
I'll see if I can help debug the problem... psake simply calls the script block provided at the appropriate time. Basically Task is a PowerShell function that queues up a task including its name, dependencies, script block, and other metadata. During the execution phase, psake executes the requested task by running its dependencies recursively and then the task itself. Execution is done using "& task.Action" where Action is the original script block provided. (e.g. The body of the task.) So I'm not understanding why execution behaviour would be different between psake and PowerShell (shell or ISE).

What is the source code for OutToStdErr.exe? I'm guessing that it outputs something to stderr. Could you provide the original source or write the equivalent function in PowerShell? Are you doing something like the following PowerShell code?

[Console]::Error.WriteLine("Hello, stderr")

I'm happy to debug through the issue, but need to be able to repro it on my own system. Looking through the files that you sent, it's unclear what I should be running at the command line to repro the problem - the actual command line to execute, the expected output, and the erroneous output.

James
--
James Kovacs, B.Sc., M.Sc.
http://jameskovacs.com
jko...@post.harvard.edu
@jameskovacs (Twitter)
403-397-3177 (mobile)
jameskovacs (Skype)










--
You received this message because you are subscribed to the Google Groups "psake-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/psake-users/-/mlm5Dx3FOXwJ.
To post to this group, send email to psake...@googlegroups.com.
To unsubscribe from this group, send email to psake-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/psake-users?hl=en.

James Dawson

unread,
Jul 3, 2012, 11:11:53 AM7/3/12
to psake...@googlegroups.com
Hi,

Was any further progress made on this?

I'm hitting the same issue when calling a command-line tool and have been able to recreate it with the following simple console app:

namespace StdErrRepro
{
    using System;
 
    class Program
    {
        static void Main(string[] args)
        {
            Console.Error.WriteLine("This is just a warning!");
        }
    }
}

From a regular PowerShell prompt:

PS C:\> & C:\StdErrRepro.exe
This is just a warning!

However, when running the same command from within a psake script:

Task default -depends StdErrRepro

Task StdErrRepro {
    & "C:\StdErrRepro.exe"    
    Write-Host "All done"
}

I get the following output:

PS C:\> invoke-psake -buildfile .\StdErrRepro.ps1
psake version 4.00
Copyright (c) 2010 James Kovacs

Executing StdErrRepro
03/07/2012 15:50:50: An Error Occurred:
StdErrRepro.exe : This is just a warning!
At C:\StdErrRepro.ps1:4 char:6
+     & <<<<  "C:\StdErrRepro.exe"
    + CategoryInfo          : NotSpecified: (This is just a warning!:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

I've read various posts indicating that the handling of StandardError varies between different hosts, this SO thread has some good detail:


...but nothing that has helped me, thus far, understand exactly why this is happening inside of psake specifically.

You can get the original example, run from a regular PowerShell prompt, to behave the same way as psake like this:

PS C:\> & C:\StdErrRepro.exe 2>&1
StdErrRepro.exe : This is just a warning!
At line:1 char:2
+ & <<<<  "C:\StdErrRepro.exe" 2>&1
    + CategoryInfo          : NotSpecified: (This is just a warning!:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Does psake do any special handling or redirection of StdErr?

Cheers,
James.



James Dawson

unread,
Jul 3, 2012, 12:30:34 PM7/3/12
to psake...@googlegroups.com
Please ignore my last post - I somehow managed to convince myself I had recreated the issue when I hadn't.

Further testing showed I was only able to recreate it when redirecting standard error to standard output, which was the premise of the referenced SO post.

My current thinking is that there must be some redirection happening elsewhere in the overall process that executes our psake script.

Apologies for the noise!

Cheers,
James.


On Tuesday, 3 July 2012 16:11:53 UTC+1, James Dawson wrote:
I'm hitting the same issue when calling a command-line tool and have been able to recreate it with the following simple console app:

<snip> 
Reply all
Reply to author
Forward
0 new messages