Forum: Ruby forcing STDOUT.sync for scripts

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
google (Guest)
on 2005-11-26 02:36
(Received via mailing list)
I'm trying to figure out a way to force STDOUT to be synchronized when
I run scripts with Ruby.  I'm using emacs and MKSNT on Windows XP, and
I can't see the output (nor give input) when I run things like the
generate script for Rails, the WEBrick server, etc. because output is
buffered.

I tried putting -e "STDOUT.sync = true" before my script invocation,
but it looks like Ruby doesn't run a given script file if the -e is
given.  Boo.

Does anyone know a way to fix this?  I can run the scripts outside of
emacs, but it's a real pain...

Frayzhe
dooby (Guest)
on 2005-11-26 03:56
(Received via mailing list)
Frayzhe wrote:
> Does anyone know a way to fix this?  I can run the scripts outside of
> emacs, but it's a real pain...
>


How about creating a "sync.rb" file in your site-ruby folder, then:

  ruby -rsync myscript.rb

?

daz
pesterhazy (Guest)
on 2005-11-27 20:37
(Received via mailing list)
daz schrieb:
> How about creating a "sync.rb" file in your site-ruby folder, then:
>
>   ruby -rsync myscript.rb

It would be great either to:

 1) ship such a module with ruby

or to

 2) provide a command line option such as python's:
  "-u: unbuffered binary stdout and stderr"

This feature is often required, such as running a script in any IDE.

Cheers,
Paulus
jeff.darklight (Guest)
on 2005-11-28 07:31
(Received via mailing list)
You could always build your sync.rb file and add it to your RUBYOPT env
variable ...

j.

On 11/27/05, Paulus E. <removed_email_address@domain.invalid> wrote:
> or to
>
--
"Remember. Understand. Believe. Yield! -> http://ruby-lang.org"

Jeff W.
pit (Guest)
on 2005-11-28 10:32
(Received via mailing list)
Paulus E. schrieb:
> or to
>
>  2) provide a command line option such as python's:
>   "-u: unbuffered binary stdout and stderr"
>
> This feature is often required, such as running a script in any IDE.

Hi Paulus,

another way is use a command line such as

   ruby -e "STDOUT.sync = true" -e "load ARGV.shift" myscript.rb

Regards,
Pit
google (Guest)
on 2005-11-28 17:50
(Received via mailing list)
This last suggestion would be great, but it doesn't work.  Ruby doesn't
run the script given at the end of the command line if you have one or
more -e switches.  This, too, seems like something that could/should be
changed...

Frayzhe
pit (Guest)
on 2005-11-28 21:25
(Received via mailing list)
Frayzhe schrieb:
> This last suggestion would be great, but it doesn't work.  Ruby doesn't
> run the script given at the end of the command line if you have one or
> more -e switches.  This, too, seems like something that could/should be
> changed...

Have you tried the command line I've shown?

Regards,
Pit
nobuyoshi.nakada (Guest)
on 2005-11-29 04:37
(Received via mailing list)
Hi,

At Mon, 28 Nov 2005 16:51:38 +0900,
Pit C. wrote in [ruby-talk:167734]:
> another way is use a command line such as
>
>    ruby -e "STDOUT.sync = true" -e "load ARGV.shift" myscript.rb

It'd be better to set $0 too.

     ruby -e STDOUT.sync=true -e 'load($0=ARGV.shift)' myscript.rb
pit (Guest)
on 2005-11-29 11:57
(Received via mailing list)
nobuyoshi nakada schrieb:
> At Mon, 28 Nov 2005 16:51:38 +0900,
> Pit C. wrote in [ruby-talk:167734]:
>
>>another way is use a command line such as
>>
>>   ruby -e "STDOUT.sync = true" -e "load ARGV.shift" myscript.rb
>
> It'd be better to set $0 too.
>
>      ruby -e STDOUT.sync=true -e 'load($0=ARGV.shift)' myscript.rb

Hi Nobu,

I didn't know you can do this. Thanks for the info! It's very useful for
my programs.

Regards,
Pit
google (Guest)
on 2005-11-30 07:50
(Received via mailing list)
Pit,

Thank you!  I dismissed your command line too quickly without looking
closely at what you were suggesting.  Your ARGV.shift trick works
great...

Frayzhe
This topic is locked and can not be replied to.