【问题标题】:How do I tell from within a ruby script whether it has been run from the command line or from a non-interactive process?如何从 ruby​​ 脚本中判断它是从命令行运行还是从非交互式进程运行?
【发布时间】:2010-07-19 13:54:52
【问题描述】:

如何从 ruby​​ 脚本中判断它是否已从命令行运行,例如:

> ruby myscript.rb

或来自非交互式进程,例如定时任务?

【问题讨论】:

    标签: ruby


    【解决方案1】:

    $stdin.tty? 如果连接到终端则返回 true,否则返回 false。

    关于问题Best practices with STDIN in Ruby?有相当多的附加信息

    【讨论】:

      猜你喜欢
      • 2010-11-09
      • 2020-03-31
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多