Stderr from container execute in Rancher API?

Hi,

I’m set out to execute simple commands in already running containers using the Rancher API and websockets.
All is good except that I can’t seem to find a way to read anything from stderr?

That is; issuing a execute request with the following payload will print my output through the websocket:

{
“tty”: false,
“command”: [
"/bin/bash",
"-c",
“echo derp”
]
}

This payload however will return nothing:

{
“tty”: false,
“command”: [
"/bin/bash",
"-c",
">&2 echo derp"
]
}

I have tried to add attachStderr: true to the payload with no difference.
Though, the documentation hints nothing about that it should be doing anything so no great surprise there really… :wink:

I guess my actual question is this: what kind of workaround can I use for executing commands through the API and read both stdout and stderr and also be able to differantiate them from each other? (I can’t with TTY enabled)

When using the logs websocket I can simply regex my way out of the situation assuming TTY is disabled but I’m assuming some kind of rewrite of output is happening server-side for that?
I would be using the logs socket also for what I try to do here but can’t since the container is already running another command.

Thank you for all the awesomeness that is rancher btw! :slight_smile:
It’s currently solving everything I need except cron-like scheduling and pipelining of several cron-like commands which is why I’m executing commands through the API in the first place.
(I’m writing a rancher plugin for rundeck but need stderr to get proper job states back in rundeck)

Anyways, thanks!

/ Klas

Never mind, I managed to solve it myself by using some inline rewrites and formatting to emulate the output format of the logs web socket.
I’m having issues still that the lines not always get printed in the same order but believe that might be a problem with my socket library rather than in Rancher itself.

Here is the monstrosity for reference:

{
“tty”: false,
“command”: [
"/bin/bash",
"-c",
"{ { echo 1; >&2 echo 2; } > >( while read line; do echo “1 $(date -u +%Y-%m-%dT%H:%M:%SZ) ${line}”; done ); } 2> >( while read line; do echo “2 $(date -u +%Y-%m-%dT%H:%M:%SZ) ${line}”; done )"
]
}

Must be a cleaner way to achieve this, no?