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

Cannot separately process stderr #23

Open
ghost opened this issue Aug 16, 2014 · 1 comment
Open

Cannot separately process stderr #23

ghost opened this issue Aug 16, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 16, 2014

execSync redirects stderr to stdout:

sh = require('execSync');
var stdout = sh.exec('echo my_error >&2').stdout;
console.log('stdout: ' + stdout); // stdout: my_error

However, it would be preferable (IMO) if it worked like this instead:

var sh = require('execSync');
var stdout = sh.exec('echo my_output').stdout;
var stderr = sh.exec('echo my_error >&2').stderr;
console.log('stdout: ' + stdout + ' ; stderr: ' + stderr); // stdout: my_output ; stderr: my_error
@jonnyreeves
Copy link

You can work around this by manually redirect stdErr and stdOut when invoking run, ie:

var stdOutTmpFile = temp.openSync("cmd-stdout").path;
var stdErrTmpFile = temp.openSync("cmd-stderr").path;

var statusCode = execSync.run(cmd + " 1> " + stdOutTmpFile + " 2> " + stdErrTmpFile);

console.log(fs.readFileSync(stdOutTmpFile.toString()));
console.log(fs.readFileSync(stdErrTmpFile.toString()));

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

1 participant