Skip to content

Instantly share code, notes, and snippets.

@joshkehn
Created February 10, 2012 15:54
Show Gist options
  • Select an option

  • Save joshkehn/1790433 to your computer and use it in GitHub Desktop.

Select an option

Save joshkehn/1790433 to your computer and use it in GitHub Desktop.
var exec = require('child_process').exec,
spawn = require('child_process').spawn;
function create_path (basename, y, m, d, callback) {
var path = [basename, y, m, d].join('/'), mkdir;
mkdir = spawn('mkdir', ['-p', path], function (err, out, err_out) {
if (err) throw err;
callback(path, {stdout: out, stderr: err_out});
});
mkdir.on('exit', function (code) {
if (code != '0') {
throw 'mkdir -p ' + path + ' failed.';
} else {
callback(path);
}
});
mkdir.stderr.on('data', function (data) {
console.log('ps stderr: ' + data);
});
}
for (var i = 0; i < 5; i++) {
for (var j = 0; j < 5; j++) {
for (var k = 0; k < 5; k++) {
create_path('./tmp', i, j, k, function done (path) {
console.log('Wrote', path);
});
}
}
}
[7557]: node emfile.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: spawn EMFILE
at errnoException (child_process.js:482:11)
at ChildProcess.spawn (child_process.js:445:11)
at child_process.js:343:9
at create_path (/Users/josh/Dropbox/Documents/blog/emfile.js:6:13)
at Object.<anonymous> (/Users/josh/Dropbox/Documents/blog/emfile.js:27:13)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment