NodeJS capture/read output of process.stdout NodeJS capture/read output of process.stdout kubernetes kubernetes

NodeJS capture/read output of process.stdout


Creating an own stream object instead of using the one from process / console works good.

var Stream = require('stream');    var ws = new Stream;ws.writable = true;ws.str = "";ws.str = 0;ws.string = function(){  return ws.str;}ws.clearStr = function(){  ws.str = "";}ws.write = function(buf) {  ws.str += buf.toString();  ws.bytes += buf.length;}ws.end = function(buf) {   if(arguments.length) ws.write(buf);   ws.writable = false;}async function kubeExec(ns, pod, container, cmd){  ws.clearStr();  ret = new Promise((resolve,reject) =>{    execV1Api.exec(ns,pod,container,cmd, ws, process.stderr , process.stdin,true /* tty */,      async function(ret){          if(ret.status == "Success"){            resolve(ws.str);          } else {            console.log(JSON.stringify(status, null, 2));          }      });  });  return ret.then( (str) => { return str;} );}