diff --git a/src/common/ttys.ts b/src/common/ttys.ts index 2a9bec9d..f71b08de 100644 --- a/src/common/ttys.ts +++ b/src/common/ttys.ts @@ -1,6 +1,6 @@ -import fs from 'fs'; -import tty from 'tty'; -import assert from 'assert'; +import fs from "fs"; +import tty from "tty"; +import assert from "assert"; // Based on https://github.com/TooTallNate/ttys/blob/master/index.js export const ttys: { @@ -11,15 +11,23 @@ export const ttys: { if (tty.isatty(0)) { ttys.stdin = process.stdin; } else { - let ttyFd = fs.openSync('/dev/tty', 'r'); - assert(tty.isatty(ttyFd)); - ttys.stdin = new tty.ReadStream(ttyFd); + try { + let ttyFd = fs.openSync("/dev/tty", "r"); + assert(tty.isatty(ttyFd)); + ttys.stdin = new tty.ReadStream(ttyFd); + } catch { + ttys.stdin = process.stdin; + } } if (tty.isatty(1)) { ttys.stdout = process.stdout; } else { - let ttyFd = fs.openSync('/dev/tty', 'w'); - assert(tty.isatty(ttyFd)); - ttys.stdout = new tty.WriteStream(ttyFd); + try { + let ttyFd = fs.openSync("/dev/tty", "w"); + assert(tty.isatty(ttyFd)); + ttys.stdout = new tty.WriteStream(ttyFd); + } catch { + ttys.stdout = process.stdout; + } }