Created
June 13, 2014 03:06
-
-
Save matutter/6e76c83cc2ac8f5819d8 to your computer and use it in GitHub Desktop.
IPC in nodeJS
This file contains hidden or 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
try { | |
var proc = cp.spawn('execs/a.out',['param1','param2'], null ); | |
proc.stdout.setEncoding('utf-8'); | |
proc.stdin.setEncoding('utf-8'); | |
var writeBuffer = [] | |
, artificial_latency = 50 | |
, writeCRON = setInterval(function(){ | |
if( /*proc.connected &&*/ writeBuffer.length ) { | |
proc.stdin.write( writeBuffer[0] + '\n') | |
console.log( 'buffer wrote ' + writeBuffer[0] ) | |
writeBuffer.shift() | |
} | |
}, artificial_latency) | |
proc.stdout.on('data',function(stream){ | |
console.log( proc.pid + ' >> ' + stream ) | |
//writeBuffer.push( (Number(stream) + 100) ) | |
}) | |
proc.stderr.on('data', function(stream) { | |
console.log( stream ) | |
}) | |
proc.on('close', function(code) { | |
console.log('exit ' + code) | |
}) | |
} catch(e) { | |
console.log(e) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment