如何从命令行打开ruby中的STDOUT.sync [英] How to turn on STDOUT.sync in ruby from the command line

查看:167
本文介绍了如何从命令行打开ruby中的STDOUT.sync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Objective-C代码,它调用ruby脚本并监视STDOUT。但是,默认情况下ruby似乎没有同步STDOUT,所以我需要在脚本开头放置 STDOUT.sync = true 以查看输出。

I have objective-C code that calls ruby scripts and monitors STDOUT. However, ruby does not seem to synchronise STDOUT by default, so I need to put STDOUT.sync = true at the beginning of the script to see output as it happens.

我可以在调用ruby脚本时将其作为命令行选项吗?

Can I do this as a command line option when calling a ruby script?

推荐答案

您可以在脚本之前创建要求的安装文件。然后使用 -r 标志调用ruby:

You can create a setup file to require before your script. Then call ruby with the -r flag:

ruby -r "$HOME/.rubyopts.rb" myscript.rb

您还可以设置环境变量 RUBYOPT 每次运行ruby时自动包含该文件:

You can also set the environment variable RUBYOPT to automatically include that file every time you run ruby:

export RUBYOPT="-r $HOME/.rubyopts.rb"

这篇关于如何从命令行打开ruby中的STDOUT.sync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆