Last active
July 1, 2018 22:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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