javascript - Pass a Buffer to a Node.js Child Process -


after went through documentation node.js child processes, curious if possible pass buffer process.

https://nodejs.org/api/child_process.html

for me seems can pass strings? how can pass buffers or objects? thanks!

you can pass buffer or string.

var node = require('child_process').spawn('node',['-i']); node.stdout.on('data',function(data) {     console.log('child:: '+string(data)); });  var buf = new buffer('console.log("woof!") || "osom\x05";\x0dprocess.exit();\x0d'); console.log('out:: ',buf.tostring()) node.stdin.write(buf); 

output:

out::  console.log("woof!") || "osom♣"; process.exit(); child:: > child:: woof!  child:: 'osom\u0005'  child:: > 

because .stdin writable stream.

\x0d(cr) 'enter' simulation in interactive mode.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -