Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

powershell errors #2

Open
wagosia opened this issue Aug 10, 2013 · 5 comments
Open

powershell errors #2

wagosia opened this issue Aug 10, 2013 · 5 comments

Comments

@wagosia
Copy link

wagosia commented Aug 10, 2013

How to catch errors,warnings, confirmation messages from powershell commands ?

@dfinke
Copy link
Owner

dfinke commented Aug 10, 2013

Thanks for the issue. Please post a small snippet of what you're trying to do. I suspect errors and warnings will be easier than confirmation messages.

Thanks
Doug

@wagosia
Copy link
Author

wagosia commented Aug 12, 2013

When executing a Powershell command it can provide standard output, error or warning. When using edge-ps, we have "result" as standard output however I don't know how to find out if the command did run properly when there is no output from Powershell command or error / warning was present.

I know that we can use errorvariable or warningwariable in order to catch them in Powershell, however how to pass them back to nodejs ?

Only way I can think of is catching -ev -we -ov into separate variables then creating a powershell object which would have result, error, warning, then convert this object into json string and pass it as "result". However this is such a long way to do it I hope that there is a better one.

My example:

var test = edge.func('ps', function() {/*
    $PARAM = "$inputFromJS" | ConvertFrom-Json;
    Get-EventLog -logname $PARAM.logname -ev ownE -wv ownW -ov ownO > $null
    $OWN = @{}
    $OWN.error = $ownE  
    $OWN.warning = $ownW
    $OWN.result = $ownO
    $OWN | ConvertTo-JSON
*/});

It's still not catching all errors :-( for example following error is not going to be "saved" into errorvariable

PS C:\Users\wagosia\Desktop> get-eventlog -logname Application -newest 5a -ev test
Get-EventLog : Cannot bind parameter 'Newest'. Cannot convert value "5a" to type "System.Int32". Error: "Input string
was not in a correct format."
At line:1 char:43
+ get-eventlog -logname Application -newest 5a -ev test
+                                           ~~
    + CategoryInfo          : InvalidArgument: (:) [Get-EventLog], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetEventLogCommand

PS C:\Users\wagosia\Desktop> $test
PS C:\Users\wagosia\Desktop>

@dfinke
Copy link
Owner

dfinke commented Aug 17, 2013

Thanks for the issue. I haven't layered in pushing errors back to node. Let me know if you'd want to take a crack at that.

@jacargentina
Copy link

I have a similar problem: if i write some syntax error on the powershell text, i have no indication of the error when back on Node. Any advance on this ?

@dfinke
Copy link
Owner

dfinke commented Nov 7, 2014

The C# that handles the PowerShell engine and runspace does not handle returning errors from the pipeline etc. That needs to be extended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants