|
140 | 140 |
|
141 | 141 | } else { |
142 | 142 | // Read all of stdin - execute it. |
143 | | - process.stdin.resume(); |
144 | 143 | process.stdin.setEncoding('utf8'); |
145 | 144 |
|
146 | 145 | var code = ''; |
|
497 | 496 | switch (tty_wrap.guessHandleType(fd)) { |
498 | 497 | case 'TTY': |
499 | 498 | var tty = NativeModule.require('tty'); |
500 | | - stdin = new tty.ReadStream(fd); |
| 499 | + stdin = new tty.ReadStream(fd, { |
| 500 | + highWaterMark: 0, |
| 501 | + lowWaterMark: 0 |
| 502 | + }); |
501 | 503 | break; |
502 | 504 |
|
503 | 505 | case 'FILE': |
504 | 506 | var fs = NativeModule.require('fs'); |
505 | | - stdin = new fs.ReadStream(null, {fd: fd}); |
| 507 | + stdin = new fs.ReadStream(null, { fd: fd }); |
506 | 508 | break; |
507 | 509 |
|
508 | 510 | case 'PIPE': |
509 | 511 | var net = NativeModule.require('net'); |
510 | | - stdin = new net.Stream(fd); |
| 512 | + stdin = new net.Stream({ fd: fd }); |
511 | 513 | stdin.readable = true; |
512 | 514 | break; |
513 | 515 |
|
|
520 | 522 | stdin.fd = fd; |
521 | 523 |
|
522 | 524 | // stdin starts out life in a paused state, but node doesn't |
523 | | - // know yet. Call pause() explicitly to unref() it. |
524 | | - stdin.pause(); |
525 | | - |
526 | | - // when piping stdin to a destination stream, |
527 | | - // let the data begin to flow. |
528 | | - var pipe = stdin.pipe; |
529 | | - stdin.pipe = function(dest, opts) { |
530 | | - stdin.resume(); |
531 | | - return pipe.call(stdin, dest, opts); |
532 | | - }; |
| 525 | + // know yet. Explicitly to readStop() it to put it in the |
| 526 | + // not-reading state. |
| 527 | + if (stdin._handle && stdin._handle.readStop) { |
| 528 | + stdin._handle.reading = false; |
| 529 | + stdin._readableState.reading = false; |
| 530 | + stdin._handle.readStop(); |
| 531 | + } |
| 532 | + |
| 533 | + // if the user calls stdin.pause(), then we need to stop reading |
| 534 | + // immediately, so that the process can close down. |
| 535 | + stdin.on('pause', function() { |
| 536 | + if (!stdin._handle) |
| 537 | + return; |
| 538 | + stdin._readableState.reading = false; |
| 539 | + stdin._handle.reading = false; |
| 540 | + stdin._handle.readStop(); |
| 541 | + }); |
533 | 542 |
|
534 | 543 | return stdin; |
535 | 544 | }); |
|
0 commit comments