commander.js: Could have error() output to stderr?
I have a command line application with the output redirected to a file.
node app.js mandatory-argument > output.dat
If mandatory-argument is not present, commander help() function is called. Unfortunately the help text goes to the output file due to the redirection. In the commander source file, the help output is hardcoded to go to stdout (line 1147).
A workaround is to call help() this way:
const cb = (hlpText: string): string => {
process.stderr.write(hlpText);
return "";
};
program.help(cb);
But should be simpler if all commander messages go to stderr and not to stdout. Thanks for looking! mario
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17
Thanks, but I solved in a different way. What I was outputting to stdout now goes to a file. Thanks again for the useful package!
This was the only way to have the help text visible when stdout is routed to a file. Anyway, for my specific program, this workaround solved the problem. Ah, and I don’t use subcommands.
I understand your points. I will continue with my workaround any time I have to redirect stdout. Thanks! mario