Skip to content

Instantly share code, notes, and snippets.

@jakub-g
Created October 19, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakub-g/65e7473f714d19c3c8b8 to your computer and use it in GitHub Desktop.
Save jakub-g/65e7473f714d19c3c8b8 to your computer and use it in GitHub Desktop.
NodeJS synchronous exec: printing output to console vs returning output from function
function execSyncPrintOutput(command, env) {
env = env || process.env;
try {
return require('child_process').execSync((command), {
stdio: 'inherit',
env: env
});
} catch (e) {
__handleExecFailure(command);
}
}
function execSyncReturnOutput(command, env) {
env = env || process.env;
try {
return require('child_process').execSync((command), {
stdio: 'pipe',
env: env
}).toString();
} catch (e) {
__handleExecFailure(command);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment