Basically what is happening is node is expecting you to be piping an entire file into stdin, so it does indeed buffer and wait for EOF before executing the script passed in from stdin.
But it sounds like maybe your're expecting to enter the REPL in this case, and enter commands one-at-a-time? I'm node v0.7.7 the "-i" flag was added to make this case work. So with node v0.7.7 or above: $ cat | node -i But this "buffering" behavior in general doesn't happen, it's only because you were attempting to pipe a script into node with no script file to run itself, so it waits for a script from stdin and executes that. If you try the same thing again with a simple script (test.js): process.stdin.setEncoding('utf8') process.stdin.resume() process.stdin.on('data', function (command) { console.log('got command: %s', command.trim()) }) and run it: $ cat | node test.js Then you can enter commands one-line-at-a-time. On Mon, Apr 23, 2012 at 3:34 AM, Adam Spragg <adam.spr...@octaltelecom.co.uk > wrote: > Hi there, > > I'm currently working on a system that passes javascript commands to > node.js > through a pipe. > > Node.js appears to buffer it's stdin under these circumstances, which is a > problem as I'm wanting to send one command, wait a few seconds, send > another, > wait a bit more, send the next, etc... - but I want the first command to be > executed as soon as it's received. > > To reproduce: > > $ cat | node > setTimeout(function() { console.log('testing'); }, 10000); > console.log('start'); > ^D > start > testing > $ > > I can pause for as long as I like between the console.log(...) line and > hitting ^D, but the 'start' never comes up until I do, and 'testing' > doesn't > appear until 10 seconds after that. > > Is there a command line switch I can use to get it to turn this buffering > off? > If not, where might I start looking through the code to patch my local copy > myself? I found what looks like the main event loop > "uv_run(uv_default_loop());" in node.cc:Node::Start(), but can't figure out > where to look next from there. > > > Thanks, > > Adam Spragg > > -- > Adam Spragg <adam.spr...@octaltelecom.co.uk> > Developer > Octal Telecom <http://www.octaltelecom.co.uk/> > > > It reverses the logical flow of conversation! > > Why? > > > No. > > > > Should I top post? > <http://www.google.com/search?q=%22top+posting%22> > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en