Created
October 19, 2015 13:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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