How to make STDOUT unbuffered, please guide me

Discussion in 'Perl Misc' started by sahana H V, Jul 9, 2009.

  1. sahana H V

    sahana H V Guest

    Hi,

    Can i make stdout associated with my own file handle as unbuffered ?
    If so can you please tell me how to do it?

    What i am trying to do is:

    open (HVS, "/<command> <cmnd_args> 2>&1 |"); <==
    at this point of time i need stdout to be unbuffered .so that command output
    should be logged to HVS in unbuffered fashion.

    Thanks,
    -Sahana
    sahana H V, Jul 9, 2009
    #1
    1. Advertising

  2. sahana H V

    david Guest

    On Jul 9, 4:57 pm, "sahana H V" <> wrote:
    > Hi,
    >
    > Can i make stdout associated with my own file handle as unbuffered ?
    > If so can you please tell me how to do it?
    >
    > What i am trying  to do is:
    >
    > open (HVS, "/<command> <cmnd_args> 2>&1 |");   <==
    > at this point of time i need stdout to be unbuffered .so that command output
    > should be logged to HVS in unbuffered fashion.
    >
    > Thanks,
    >  -Sahana


    perldoc -q unbuffer
    david, Jul 9, 2009
    #2
    1. Advertising

  3. sahana H V wrote:
    > Hi,
    >
    > Can i make stdout associated with my own file handle as unbuffered ?
    > If so can you please tell me how to do it?
    >
    > What i am trying to do is:
    >
    > open (HVS, "/<command> <cmnd_args> 2>&1 |"); <==
    > at this point of time i need stdout to be unbuffered .so that command output
    > should be logged to HVS in unbuffered fashion.


    You can't, unless you have control over the command.

    It's the binary of the command (more precise: the stdio library linked
    to the command) which does the buffering and if stdout is not connected
    to a terminal (and a pipe is *not* a terminal), it will buffer its output.

    Josef
    --
    These are my personal views and not those of Fujitsu Technology Solutions!
    Josef Möllers (Pinguinpfleger bei FTS)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://de.ts.fujitsu.com/imprint.html
    Josef Moellers, Jul 9, 2009
    #3
  4. Ben Morrow wrote:
    > Quoth Josef Moellers <>:
    >> sahana H V wrote:
    >>> Can i make stdout associated with my own file handle as unbuffered ?
    >>> If so can you please tell me how to do it?
    >>>
    >>> What i am trying to do is:
    >>>
    >>> open (HVS, "/<command> <cmnd_args> 2>&1 |"); <==
    >>> at this point of time i need stdout to be unbuffered .so that command output
    >>> should be logged to HVS in unbuffered fashion.

    >> You can't, unless you have control over the command.
    >>
    >> It's the binary of the command (more precise: the stdio library linked
    >> to the command) which does the buffering and if stdout is not connected
    >> to a terminal (and a pipe is *not* a terminal), it will buffer its output.

    >
    > You could try using IO::Run's ">pty>" syntax, or using a pty yourself.


    Maybe Expect is an option if the OP needs to parse the command's output.

    Josef
    --
    These are my personal views and not those of Fujitsu Technology Solutions!
    Josef Möllers (Pinguinpfleger bei FTS)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://de.ts.fujitsu.com/imprint.html
    Josef Moellers, Jul 10, 2009
    #4
    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. Elad
    Replies:
    0
    Views:
    401
  2. uljanow
    Replies:
    3
    Views:
    602
    Larry Barowski
    Aug 10, 2007
  3. Yang Zhang

    Unbuffered stdout/auto-flush

    Yang Zhang, Jun 21, 2008, in forum: Python
    Replies:
    1
    Views:
    438
  4. Andreas S
    Replies:
    3
    Views:
    244
    Eric Hodel
    Dec 9, 2006
  5. Jai
    Replies:
    1
    Views:
    55
    Mark Lawrence
    Dec 11, 2013
Loading...

Share This Page