bug? ruby doesn't flush stdio on exit!

Discussion in 'Ruby' started by Sam Roberts, Mar 17, 2005.

  1. Sam Roberts

    Sam Roberts Guest

    This can't be a feature... stdio should flush on exit!

    % ruby -e 'printf "hello"'
    % ruby -e 'printf "hello\n"'
    hello
    % ruby -e 'printf "hello";puts "hi";'
    hellohi
    %

    Sam
    Sam Roberts, Mar 17, 2005
    #1
    1. Advertising

  2. Sam Roberts

    Aredridel Guest

    On Thu, 17 Mar 2005 10:34:47 +0900, Sam Roberts <> wrote:
    > This can't be a feature... stdio should flush on exit!
    >
    > % ruby -e 'printf "hello"'
    > % ruby -e 'printf "hello\n"'
    > hello
    > % ruby -e 'printf "hello";puts "hi";'
    > hellohi
    > %


    In the first example, your shell is overwriting the output.

    Not a bug.
    Aredridel, Mar 17, 2005
    #2
    1. Advertising

  3. Sam Roberts

    Sam Roberts Guest

    Quoting , on Thu, Mar 17, 2005 at 10:38:26AM +0900:
    > On Thu, 17 Mar 2005 10:34:47 +0900, Sam Roberts <> wrote:
    > > This can't be a feature... stdio should flush on exit!
    > >
    > > % ruby -e 'printf "hello"'
    > > % ruby -e 'printf "hello\n"'
    > > hello
    > > % ruby -e 'printf "hello";puts "hi";'
    > > hellohi
    > > %

    >
    > In the first example, your shell is overwriting the output.


    You're right, thanks!

    And I'm pretty surprised.

    > Not a bug.


    I think it is - a bug in zsh.

    start with bash:

    [ensemble] ~/p/ruby/zeroconf $ ruby -e 'print "hello"'
    hello[ensemble] ~/p/ruby/zeroconf $ zsh
    ensemble% ruby -e 'printf "hello"'
    ensemble%


    I think zsh is wrong here..

    Cheers,
    Sam
    Sam Roberts, Mar 17, 2005
    #3
  4. Sam Roberts

    Lloyd Zusman Guest

    Sam Roberts <> writes:

    > This can't be a feature... stdio should flush on exit!
    >
    > % ruby -e 'printf "hello"'
    > % ruby -e 'printf "hello\n"'
    > hello
    > % ruby -e 'printf "hello";puts "hi";'
    > hellohi
    > %


    It does flush. Try doing this:

    % ruby -e 'printf "hello"'; echo ''
    hello

    What's going on is that your shell is overwriting the "hello" that
    indeed gets written on the next line, when it repositions the cursor to
    the left column. Adding the "; echo ''" to the end shows that this is
    taking place.


    --
    Lloyd Zusman

    God bless you.
    Lloyd Zusman, Mar 17, 2005
    #4
  5. Sam Roberts

    Jos Backus Guest

    Also, check out

    setopt nopromptcr

    in the zsh docs.

    hal:~% setopt promptcr # default
    hal:~% echo -n hi
    hal:~% setopt nopromptcr
    hal:~% echo -n hi
    hihal:~%

    --
    Jos Backus
    jos at catnook.com
    Jos Backus, Mar 17, 2005
    #5
  6. Aredridel <> wrote:
    > > This can't be a feature... stdio should flush on exit!
    > >
    > > % ruby -e 'printf "hello"'
    > > % ruby -e 'printf "hello\n"'
    > > hello
    > > % ruby -e 'printf "hello";puts "hi";'
    > > hellohi
    > > %

    >
    > In the first example, your shell is overwriting the output.
    >
    > Not a bug.


    How did you diagnose his problem, out of curiosity?

    Cheers,
    Navin.
    Navindra Umanee, Mar 17, 2005
    #6
  7. Sam Roberts

    Sam Roberts Guest

    Quoting , on Thu, Mar 17, 2005 at 11:35:01AM +0900:
    > Also, check out
    >
    > setopt nopromptcr
    >
    > in the zsh docs.


    Great! zsh hasn't let me down until now, I'm glad I can fix this.

    Sam

    > hal:~% setopt promptcr # default
    > hal:~% echo -n hi
    > hal:~% setopt nopromptcr
    > hal:~% echo -n hi
    > hihal:~%
    >
    > --
    > Jos Backus
    > jos at catnook.com
    >
    Sam Roberts, Mar 17, 2005
    #7
  8. Hi,

    In message "Re: bug? ruby doesn't flush stdio on exit!"
    on Thu, 17 Mar 2005 11:45:08 +0900, Navindra Umanee <> writes:

    |> In the first example, your shell is overwriting the output.
    |> Not a bug.
    |
    |How did you diagnose his problem, out of curiosity?

    I guess he had same experience, like myself.

    matz.
    Yukihiro Matsumoto, Mar 17, 2005
    #8
  9. "Sam Roberts" <> schrieb im Newsbeitrag
    news:...
    > Quoting , on Thu, Mar 17, 2005 at 10:38:26AM +0900:
    > > On Thu, 17 Mar 2005 10:34:47 +0900, Sam Roberts

    <> wrote:
    > > > This can't be a feature... stdio should flush on exit!
    > > >
    > > > % ruby -e 'printf "hello"'
    > > > % ruby -e 'printf "hello\n"'
    > > > hello
    > > > % ruby -e 'printf "hello";puts "hi";'
    > > > hellohi
    > > > %

    > >
    > > In the first example, your shell is overwriting the output.

    >
    > You're right, thanks!
    >
    > And I'm pretty surprised.
    >
    > > Not a bug.

    >
    > I think it is - a bug in zsh.
    >
    > start with bash:
    >
    > [ensemble] ~/p/ruby/zeroconf $ ruby -e 'print "hello"'
    > hello[ensemble] ~/p/ruby/zeroconf $ zsh
    > ensemble% ruby -e 'printf "hello"'
    > ensemble%
    >
    >
    > I think zsh is wrong here..


    It's probably just the promt setting. If the prompt starts with a CR then
    old content of the line is overwritten.

    robert
    Robert Klemme, Mar 17, 2005
    #9
  10. * Robert Klemme (Mar 17, 2005 10:10):
    > > I think it is - a bug in zsh.
    > >
    > > start with bash:
    > >
    > > [ensemble] ~/p/ruby/zeroconf $ ruby -e 'print "hello"'
    > > hello[ensemble] ~/p/ruby/zeroconf $ zsh
    > > ensemble% ruby -e 'printf "hello"'
    > > ensemble%
    > >
    > >
    > > I think zsh is wrong here..


    Wow, amazing how everything is a bug. Bugs, bugs, bugs...Bugs
    everywhere!

    > It's probably just the promt setting. If the prompt starts with a CR then
    > old content of the line is overwritten.


    Precisely. Zsh must know where it begins printing the prompt (and its
    absolute width) to know when it has reached the right end of the
    terminal (so that it can do proper wrapping or shifting). There's a
    promptcr module for Zsh that outputs a newline before printing the
    prompt, thus output is never overwritten. It's not very good, though.

    See http://rubyurl.com/InP9S for a discussion on an alternative solution
    to using promptcr,
    nikolai

    --
    ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
    ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
    ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
    main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
    Nikolai Weibull, Mar 17, 2005
    #10
  11. * Nikolai Weibull (Mar 17, 2005 10:25):
    > … There's a promptcr module for Zsh that outputs a newline before
    > printing the prompt, thus output is never overwritten. …


    Actually, it's called promptnl, not promptcr; sorry,
    nikolai

    --
    ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
    ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
    ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
    main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
    Nikolai Weibull, Mar 17, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,898
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Joe Smith
    Replies:
    4
    Views:
    65,841
    sandeep1976
    Nov 8, 2006
  3. Replies:
    2
    Views:
    455
    Jeff Epler
    May 31, 2005
  4. Replies:
    18
    Views:
    1,903
    crazzybugger
    Oct 22, 2006
  5. chad
    Replies:
    14
    Views:
    578
    Arnaud Delobelle
    Oct 13, 2010
Loading...

Share This Page