From 2470081789ea95f0a594cf462395ce1e9cbbb3a7 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 12 Aug 2019 15:30:07 -0500 Subject: [PATCH] Exit when pipe closes This allows piping to things like `head` without SIGPIPE errors. --- src/cli.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cli.ts b/src/cli.ts index 54c1c7e1..28b46487 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -229,6 +229,12 @@ const main = async(): Promise => { 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);