Last active
April 14, 2019 17:04
-
-
Save boopathi/806ef59c346cb789a21b to your computer and use it in GitHub Desktop.
File descriptors - stdin and stdout - isTTY ? in a forked process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Case I: node parent | |
Parent: true From tty: true | |
Parent: true From tty: true | |
TTY: true From tty: true | |
TTY: true From tty: true | |
Case II: node parent > asdf | |
Parent: true From tty: true | |
Parent: undefined From tty: true | |
TTY: true From tty: true | |
TTY: undefined From tty: true | |
Case III: cat asdf | node parent | |
Parent: undefined From tty: false | |
Parent: true From tty: false | |
TTY: undefined From tty: false | |
TTY: true From tty: false | |
Case IV: cat asdf | node parent > asdf | |
Parent: undefined From tty: false | |
Parent: undefined From tty: false | |
TTY: undefined From tty: false | |
TTY: undefined From tty: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cp = require('child_process'); | |
var tty = require('tty'); | |
cp.fork('./tty.js'); | |
console.log("Parent: ", process.stdin.isTTY, " From tty: ", tty.isatty(process.stdin)); | |
console.log("Parent: ", process.stdout.isTTY, " From tty: ", tty.isatty(process.stdout)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Case I: node parent" | |
node parent | |
echo "" | |
echo "Case II: node parent > asdf" | |
node parent > asdf | |
cat asdf | |
echo "" | |
echo "Case III: cat asdf | node parent" | |
cat asdf | node parent | |
echo "" | |
echo "Case IV: cat asdf | node parent > asdf" | |
cat asdf | node parent > asdf | |
cat asdf | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tty = require('tty'); | |
console.log("TTY: ", process.stdin.isTTY, " From tty: ", tty.isatty(process.stdin)); | |
console.log("TTY: ", process.stdout.isTTY, " From tty: ", tty.isatty(process.stdout)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment