how to control stdout buffer??

Discussion in 'Perl Misc' started by sonet, Jan 14, 2005.

  1. sonet

    sonet Guest

    #!/usr/bin/perl
    $|=1;
    print "Content-Type: text/plain\r\n\r\n";
    print `ldapsearch -b dc=abc,dc=edu -D cn=Manager,dc=abc,dc=edu -w abc -h
    ldap.abc.edu -LLL "uid=*"`;

    If i do this job in unix comand ,the stdout will continue output.
    But if i do this job in cgi,the stdout will pause to output until the
    ldapsearch complete.
    And this process will cost about 10 mins.
    How to control the cgi stdout buffer?
     
    sonet, Jan 14, 2005
    #1
    1. Advertising

  2. "sonet" <> wrote in
    news:cs7g9d$sv9$:

    > #!/usr/bin/perl
    > $|=1;
    > print "Content-Type: text/plain\r\n\r\n";
    > print `ldapsearch -b dc=abc,dc=edu -D cn=Manager,dc=abc,dc=edu -w abc
    > -h ldap.abc.edu -LLL "uid=*"`;
    >
    > If i do this job in unix comand ,the stdout will continue output.
    > But if i do this job in cgi,the stdout will pause to output until the
    > ldapsearch complete.


    The output is not being paused. You have told perl to read all the lines
    output by ldapsearch and then print them rather than reading the output
    of ldapsearch line by line.

    > And this process will cost about 10 mins.
    > How to control the cgi stdout buffer?


    I am not sure exactly what you are asking, but, either:

    http://www.stonehenge.com/merlyn/LinuxMag/col39.html

    or

    #! perl

    $| = 1;

    use strict;
    use warnings;

    open my $ls, 'ls -l . |'
    or die "Cannot open pipe to ls: $!";

    while(<$ls>) {
    print;
    sleep 1;
    }

    close $ls
    or die "Cannot close pipe to ls: $!";

    __END__

    might help.

    See perldoc perlopentut and perldoc perlipc for more information on
    pipes. Clearly, you would open a pipe to the command whose output you are
    interested in rather than to ls.

    Sinan.
     
    A. Sinan Unur, Jan 14, 2005
    #2
    1. Advertising

  3. sonet

    sonet Guest

    sorry , my english is poor!

    Thanks.
    But the method will occur <defunct> in linux,
    if the command is not terminate and httpd connection close.



    "A. Sinan Unur" <> ¦b¶l¥ó
    news:Xns95DDEFC6E689Casu1cornelledu@132.236.56.8 ¤¤¼¶¼g...
    > "sonet" <> wrote in
    > news:cs7g9d$sv9$:
    >
    > > #!/usr/bin/perl
    > > $|=1;
    > > print "Content-Type: text/plain\r\n\r\n";
    > > print `ldapsearch -b dc=abc,dc=edu -D cn=Manager,dc=abc,dc=edu -w abc
    > > -h ldap.abc.edu -LLL "uid=*"`;
    > >
    > > If i do this job in unix comand ,the stdout will continue output.
    > > But if i do this job in cgi,the stdout will pause to output until the
    > > ldapsearch complete.

    >
    > The output is not being paused. You have told perl to read all the lines
    > output by ldapsearch and then print them rather than reading the output
    > of ldapsearch line by line.
    >
    > > And this process will cost about 10 mins.
    > > How to control the cgi stdout buffer?

    >
    > I am not sure exactly what you are asking, but, either:
    >
    > http://www.stonehenge.com/merlyn/LinuxMag/col39.html
    >
    > or
    >
    > #! perl
    >
    > $| = 1;
    >
    > use strict;
    > use warnings;
    >
    > open my $ls, 'ls -l . |'
    > or die "Cannot open pipe to ls: $!";
    >
    > while(<$ls>) {
    > print;
    > sleep 1;
    > }
    >
    > close $ls
    > or die "Cannot close pipe to ls: $!";
    >
    > __END__
    >
    > might help.
    >
    > See perldoc perlopentut and perldoc perlipc for more information on
    > pipes. Clearly, you would open a pipe to the command whose output you are
    > interested in rather than to ls.
    >
    > Sinan.
     
    sonet, Jan 14, 2005
    #3
    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:
    437
  2. JohnF

    redirect system() stdout to buffer

    JohnF, Sep 21, 2007, in forum: C Programming
    Replies:
    6
    Views:
    882
  3. Ecir Hana

    Redirect stdout to a buffer

    Ecir Hana, Nov 15, 2009, in forum: Python
    Replies:
    6
    Views:
    3,178
    Ecir Hana
    Dec 10, 2009
  4. Andreas S
    Replies:
    3
    Views:
    287
    Eric Hodel
    Dec 9, 2006
  5. Replies:
    2
    Views:
    383
    A. Sinan Unur
    Dec 7, 2005
Loading...

Share This Page