Running a powershell command redirects the output to the stderr in the case that isn't needed

54 views Asked by At

I am calling this command in powershell: docker logs imagela-cpu-container_03 2>&1.It looks that powershell is redirecting the output of this command to the stderr on calling.This are the logs that are displayed in the container and I want on the process of the command to not detect this as an error of the command.If i run the command like this from my C# code: docker logs imagela-cpu-container_03 ,than i am not getting any data from it and the powershell is registering the data as an error

    docker : Unexpected connection close from remote 
    "ampq://Alejandro:******@x:x/vhost%20Ali", Connection.Close(reply_code=320, 
    reply_text="CONNECTION_FORCED - broker forced connection
    closure with reason 'shutdown'")
    Aline:1 char:1
    + docker logs imagela-cpu-container_03 2>&1
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Unexpected conn...on 'shutdown'"):String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

NoneType: None
Connection attempt to "ampq://Alejandro:******@x:x/vhost%20Ali" failed: Server connection unexpectedly closed. Reconnecting after 5 seconds.
Connection attempt to "ampq://Alejandro:******@x:x/vhost%20Ali" failed: [Errno 111] Connect call failed ('192.168.51.48', 5672). Reconnecting after 5 seconds.
Connection attempt to "ampq://Alejandro:******@x:x/vhost%20Ali" failed: [Errno 111] Connect call failed ('192.168.51.48', 5672). Reconnecting after 5 seconds.
Connection attempt to "ampq://Alejandro:******@x:x/vhost%20Ali" failed: Server connection unexpectedly closed. Reconnecting after 5 seconds.
Connection attempt to "ampq://Alejandro:******@x:x/vhost%20Ali" failed: Server connection unexpectedly closed. Reconnecting after 5 seconds.

I know that the messages that i receive are error messages but i want to get this data and log them in a file and there not be treated as an error message from powershell.

1

There are 1 answers

0
KG-DROID On

Sorry I cant comment yet (dont have 50 rep to comment yet), so posting as an answer.

I'm assuming that "docker" is an exe? Have you tried running it like:

$ExeOutput = & docker logs imagela-cpu-container_03 2>&1

For some exes that will put the value of the output of the exe into the PS variable, if that's what your wanting?