Skip to content

Commit 2470081

Browse files
committed
Exit when pipe closes
This allows piping to things like `head` without SIGPIPE errors.
1 parent c11d5fe commit 2470081

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/cli.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ const main = async(): Promise<boolean | void | void[]> => {
229229
return startCli() || new WrapperProcess().start();
230230
};
231231

232+
// It's possible that the pipe has closed (for example if you run code-server
233+
// --version | head -1). Assume that means we're done.
234+
if (!process.stdout.isTTY) {
235+
process.stdout.on("error", () => process.exit());
236+
}
237+
232238
main().catch((error) => {
233239
logger.error(error.message);
234240
process.exit(typeof error.code === "number" ? error.code : 1);

0 commit comments

Comments
 (0)