r/shittyprogramming • • Aug 28 '18

Workarounds

Post image
74 Upvotes

9 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Aug 28 '18

I'm interested in how you've redirected stuff. Can you please show us?

2

u/[deleted] Aug 29 '18

I had to run a command in a docker container and I am using dockerode (a wrapper for the docker api for nodejs). When you run a command in a container using dockerode you get a readable stream. So i added the code from the image to my command and it would return one simple string where I can seperate stderr and stdout using that "PLS_DONT_HAX_ME" part as a seperation point.

But that is a HORRIBLE way to do it so I just the stream into a stderr and stdout stream using a command in dockerode and read those 2 streams seperately, when new data came into the stream I added it to a string and waited for more. After the stream ended returned the strings. That's the best soulution I found.

Here is the code: https://imgur.com/a/rBVa4Jk

I am a noob programmer so don't judge me :)