Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some callbacks to child_process.exec are never called #26

Open
joshterrell805 opened this issue Sep 16, 2014 · 1 comment
Open

Some callbacks to child_process.exec are never called #26

joshterrell805 opened this issue Sep 16, 2014 · 1 comment

Comments

@joshterrell805
Copy link

If execSync.exec is used before node's child_process.exec, the exec callback to child_process.exec is never called.

This only happens when multiple calls to execSync and child_process.exec are invoked one after the other.

Example script to demonstrate the issue:

 var exec = require('child_process').exec,
     execSync = require('execSync');

 var executions = 5;

 var execFunctions = [];

 for (var i = 0; i < executions; ++i) {
    addExecFunction(i);
 }

 var completedExecutions = 0;
 execFunctions.forEach(function(execFunction) {
    execFunction(function(err, val) {
       if (++completedExecutions == executions) {
          console.log('all complete!');
       }
    });
 });

 function addExecFunction(i) {
    execFunctions.push(function(callback) {
       console.log(i + ' start');
       var pwd = execSync.exec('cd && pwd').stdout.replace('\n', '');
       //var pwd = '~';
       var command = 'ls -l ' + pwd;
       //console.log(command);
       exec(command, function onProcessTermination(err, stdout, stderr) {
          console.log(i + ' complete');
          callback(null, i);
       });
    });
 }

output:

$ node testExec.js
0 start
1 start
2 start
3 start
4 start
3 complete
4 complete

When commenting out var pwd = execSync.exec(...);, and uncommenting var pwd = '~'; the script works fine.

PS: I'm running this on a linux box.

@danielbeardsley
Copy link

This is pretty serious. This module effectively breaks the process.exec() function when used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants