gpt4 book ai didi

ruby - #tty 是什么?在 STDIN 上意味着/在 ruby​​ 中做什么?

转载 作者:数据小太阳 更新时间:2023-10-29 07:07:01 25 4
gpt4 key购买 nike

阅读 ruby​​ 文档并没有多大帮助 here :

Returns true if ios is associated with a terminal device (tty), falseotherwise.

我希望得到一些额外的资源或解释来帮助我更好地理解这一点。

对于上下文,我正在编写一个小的命令行程序,它接受文件路径或管道内容到 ruby​​ 可执行文件中,并使用 #tty? 来确定传入的内容。

最佳答案

好像http://www.jstorimer.com/blogs/workingwithcode/7766125-writing-ruby-scripts-that-respect-pipelines#tty? 的作用提供了最简洁的描述:

Ruby's IO#isatty method (aliased as IO#tty?) will tell you whether or not the IO in question is attached to a terminal. Calling it on $stdout, for instance, when it's being piped will return false.

以下是一些您可能会觉得有用的相关信息:

背景意义来自What do pty and tty mean? :

In UNIX, /dev/tty* is any device that acts like a "teletype", ie, terminal. (Called teletype because that's what we had for terminals in those benighted days.)

本着问题的精神,这里有一个从http://zetcode.com/lang/rubytutorial/io/写入/dev/tty的例子。 :

#!/usr/bin/ruby

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

关于ruby - #tty 是什么?在 STDIN 上意味着/在 ruby​​ 中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38031949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com