简体   繁体   中英

How to turn on STDOUT.sync in ruby from the command line

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.

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM