Exit when pipe closes

This allows piping to things like `head` without SIGPIPE errors.
This commit is contained in:
Asher 2019-08-12 15:30:07 -05:00
parent c11d5fe9e6
commit 2470081789
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
1 changed files with 6 additions and 0 deletions

View File

@ -229,6 +229,12 @@ const main = async(): Promise<boolean | void | void[]> => {
return startCli() || new WrapperProcess().start();
};
// It's possible that the pipe has closed (for example if you run code-server
// --version | head -1). Assume that means we're done.
if (!process.stdout.isTTY) {
process.stdout.on("error", () => process.exit());
}
main().catch((error) => {
logger.error(error.message);
process.exit(typeof error.code === "number" ? error.code : 1);