Skip to content

Instantly share code, notes, and snippets.

@constvoidblog
Last active July 1, 2018 22:27
Show Gist options
  • Save constvoidblog/c1ee63a27d2a77d894cd06960378bbc9 to your computer and use it in GitHub Desktop.
Save constvoidblog/c1ee63a27d2a77d894cd06960378bbc9 to your computer and use it in GitHub Desktop.
Ingest spawn output in realtime, processing stdout/stderr as the spawned command emits output.
exec_realtime_io(cmd,log_cb,param_array,process_stdout_cb,process_stderr_cb,close_cb) {
var stdout='';
var stderr='';
log_cb(`running ${cmd} ${param_array}`);
var c = spawn(cmd,param_array);
c.stdout.on('data',(data)=> { stdout+=data; process_stdout_cb(data); });
c.stderr.on('data',(data)=> { stderr+=data; process_stderr_cb(data); });
c.on('close',(code)=>{ close_cb(code, stdout, stderr);});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment