How to enable STDOUT.sync in ruby ​​from the command line

I have objective-C code that calls ruby ​​scripts and tracks STDOUT. However, apparently, Ruby does not synchronize STDOUT by default, so I need to put STDOUT.sync = true at the beginning of the script to see the output of how this happens.

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

+4
source share
1 answer

You can create the installation file required before the script. Then call ruby ​​with the -r flag:

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

You can also set the RUBYOPT environment RUBYOPT to automatically include this file every time ruby ​​starts:

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

Source: https://habr.com/ru/post/906231/


All Articles