What is #tty? by STDIN means / do in ruby?

Reading ruby ​​documents is not very useful here :

Returns true if ios is connected to a terminal device (tty), false otherwise.

I was hoping to get additional resources or explanations to help me understand this better.

In the context, I write a small command-line program that takes either the path to the file or the contents of the pipeline to the ruby ​​executable, and I use it #tty?to determine what is included.

Thank!

+4
source share
2 answers

, http://www.jstorimer.com/blogs/workingwithcode/7766125-writing-ruby-scripts-that-respect-pipelines , #tty? :

Ruby IO # isatty ( IO # tty?) , IO . $stdout, , , false.

, :

pty tty?:

UNIX/dev/tty * - , "", .. . ( , , .)

, /dev/tty http://zetcode.com/lang/rubytutorial/io/:

#!/usr/bin/ruby

fd = IO.sysopen "/dev/tty", "w"
ios = IO.new(fd, "w")
ios.puts "ZetCode"
ios.close
+3

, grep UNIX: ? $stdin TTY, , - . , STDIN.

tty? , , , escape- ANSI, , . , - STDIN.

0

All Articles