2

How to detect if the type of the process.stdout/stdin is a terminal or a pipe/file? A snipped in JavaScript is required:

function isTerminal(){ ...... } 

1 Answer 1

3

The easiest way to identity if the type of the process.stdout is a pipe/file would be process.stdout.isTTY (0.8 +):

$ node -p -e "Boolean(process.stdout.isTTY)" | cat false $ node -p -e "Boolean(process.stdout.isTTY)" true 

You can also test the following with the tty module for finer grained control:

if (require('tty').isatty(1)) { // terminal } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.