-
Notifications
You must be signed in to change notification settings - Fork 739
Closed
Labels
execIssues specific to the shell.exec() APIIssues specific to the shell.exec() APIfixBug/defect, or a fix for such a problemBug/defect, or a fix for such a problem
Milestone
Description
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!
Metadata
Metadata
Assignees
Labels
execIssues specific to the shell.exec() APIIssues specific to the shell.exec() APIfixBug/defect, or a fix for such a problemBug/defect, or a fix for such a problem