Note that there are some explanatory texts on larger screens.

plurals
  1. POError running example code in a serialized loop
    primarykey
    data
    text
    <p>I have been tinkering around with node a little, and while trying to learn the child_process module, I ran into a problem. I was attempting to serialize many calls to 'ps -eF | grep ssh', but it crashes on my system with the error below. So two questions. First, is there a better way to do what I am attempting without a library? Second, why isn't it working :)</p> <pre><code>events.js:71 throw arguments[1]; // Unhandled 'error' event ^ Error: This socket is closed. at Socket._write (net.js:519:19) at Socket.write (net.js:511:15) at Socket.&lt;anonymous&gt; (/home/me/tmp/test.js:10:16) at Socket.EventEmitter.emit (events.js:96:17) at Pipe.onread (net.js:397:14) </code></pre> <pre><code>function callpsgrep(callback) { var spawn = require('child_process').spawn, ps = spawn('ls', ['-la']), grep = spawn('grep', ['bananas']); ps.stdout.on('data', function (data) { grep.stdin.write(data); }); ps.stderr.on('data', function (data) { console.log('ps stderr: ' + data); }); ps.on('exit', function (code) { if (code !== 0) { console.log('ps process exited with code ' + code); } grep.stdin.end(); }); grep.stdout.on('data', function (data) { console.log('' + data); }); grep.stderr.on('data', function (data) { console.log('grep stderr: ' + data); }); grep.on('exit', function (code) { if (code !== 0) { console.log('grep process exited with code ' + code); } callback(); }); } function series(i) { if (i &lt; 1000) { callpsgrep( function() { return series(i+1); }); } } series(0); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload