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

Synchronous exec stalls permenantly when there is an error/w the shell #7

Closed
celer opened this issue Mar 28, 2012 · 2 comments
Closed
Labels
exec Issues specific to the shell.exec() API fix Bug/defect, or a fix for such a problem
Milestone

Comments

@celer
Copy link

celer commented Mar 28, 2012

This ShellJS script will stall indefinitely, if 'nosuchfile.txt' doesn't exist.

require('shelljs/global')

exec("cat < nosuchfile.txt")

Will cause shelljs to stall

This fixes it:

  cmd += ' > '+stdoutFile+' 2>&1'; // works on both win/unix

  var script =
   "var child = require('child_process'), path=require('path'), \
        fs = require('fs'); \
    child.exec('"+escape(cmd)+"', {env: process.env}, function(err,stdout,stderr) { \
      fs.writeFileSync('"+escape(codeFile)+"', err ? err.code.toString() : '0'); \
      if(!path.existsSync('"+escape(stdoutFile)+"')){ fs.writeFileSync('"+escape(stdoutFile)+"',stdout.toString()+stderr.toString()); }; \
    }); \
    process.on('uncaughtException',function(err){ \
      if(!path.existsSync('"+escape(stdoutFile)+"')){ fs.writeFileSync('"+escape(stdoutFile)+"',err.toString()); } \
      if(!path.existsSync('"+escape(codeFile)+"')){ fs.writeFileSync('"+escape(codeFile)+"','-1'); } \
    }); \
    process.on('exit',function(){ \
      if(!path.existsSync('"+escape(stdoutFile)+"')){ fs.writeFileSync('"+escape(stdoutFile)+"','Uncaught ShellJS Error'); } \
      if(!path.existsSync('"+escape(codeFile)+"')){ fs.writeFileSync('"+escape(codeFile)+"','-1'); } \
    });"


  if (fs.existsSync(scriptFile)) _unlinkSync(scriptFile);
  if (fs.existsSync(stdoutFile)) _unlinkSync(stdoutFile);
  if (fs.existsSync(codeFile)) _unlinkSync(codeFile);

We have forked your repo, here: https://github.com/croteb/shelljs and will be keeping it current with our fixes.

Thanks!

@ariporad ariporad removed the bug label Jan 9, 2016
@nfischer nfischer added this to the v0.7.0 milestone Feb 9, 2016
@nfischer nfischer added fix Bug/defect, or a fix for such a problem exec Issues specific to the shell.exec() API labels Feb 9, 2016
@nfischer
Copy link
Member

nfischer commented Feb 9, 2016

@celer would you be able to open this as a PR? I'd love to take a look!

@nfischer nfischer modified the milestones: v0.7.0, v0.8.0 Mar 11, 2016
@nfischer
Copy link
Member

Closing this, since the relevant code path is no longer supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exec Issues specific to the shell.exec() API fix Bug/defect, or a fix for such a problem
Projects
None yet
Development

No branches or pull requests

3 participants