open (RES, "/usr/bin/top -bs -n 1 |");

Discussion in 'Perl Misc' started by Sandrine CHEN, Sep 16, 2003.

  1. Thank you to tell me why:

    I have one program like following, it could display results on HTML
    page on one machine, but not on another which has the same kernel of
    2.4.18-3, Redhat Linux, I star to wonder is it that i haven't written
    the program in a way more popular, or there is other point that i need
    to check or take care?

    What's more, on the same machine(that result couldn't display), if i
    run the script manually under command line, it couldn't display
    results. :( Why!

    ____________________________________________
    #!/usr/bin/perl -w

    print "Content-type: text/html\n\n";
    print "<html>\n";
    print "<test of result>";
    print "<body>";

    open (RES, "/usr/bin/top -bs -n 1 |");
    while (<RES>) {
    print $_,"<br>";
    }
    close RES;

    print "</body>";
    ____________________________________________

    thank u very much...
    print "</html>";
    Sandrine CHEN, Sep 16, 2003
    #1
    1. Advertising

  2. Sandrine CHEN

    Anno Siegel Guest

    Sandrine CHEN <> wrote in comp.lang.perl.misc:
    > Thank you to tell me why:
    >
    > I have one program like following, it could display results on HTML
    > page on one machine, but not on another which has the same kernel of
    > 2.4.18-3, Redhat Linux, I star to wonder is it that i haven't written
    > the program in a way more popular, or there is other point that i need
    > to check or take care?
    >
    > What's more, on the same machine(that result couldn't display), if i
    > run the script manually under command line, it couldn't display
    > results. :( Why!


    So obviously there is a difference between the two machines.

    What does it mean when you say "couldn't display results"? Does the
    program show no output at all? Does it show part of the expected
    output, and if so, where does it stop. Does the program finish normally,
    finish with a return code, or not finish at all (hang)?

    Without you telling us more, there is no chance of guessing what the
    difference may be.

    > ____________________________________________
    > #!/usr/bin/perl -w
    >
    > print "Content-type: text/html\n\n";
    > print "<html>\n";
    > print "<test of result>";
    > print "<body>";
    >
    > open (RES, "/usr/bin/top -bs -n 1 |");


    You should check the return value of open(). That may give you
    a first hint.

    > while (<RES>) {
    > print $_,"<br>";
    > }
    > close RES;
    >
    > print "</body>";
    > ____________________________________________
    >
    > thank u very much...
    > print "</html>";


    Anno
    Anno Siegel, Sep 16, 2003
    #2
    1. Advertising

  3. Sandrine CHEN <> wrote:
    >
    > open (RES, "/usr/bin/top -bs -n 1 |");
    > while (<RES>) {
    > print $_,"<br>";
    > }
    > close RES;
    >


    The error-checking for piped open works like this:

    #
    # open can also fail on fork(), pipe() or exec()
    #

    open my $top, '-|', qw(/usr/bin/top -bs -n 1)
    or die "Couldn't start top: $!";

    print while <$top>;

    #
    # close also fails if wait() yields nonzero exit status
    #

    close($top) or die "close: ", $! || $?;

    Without any error checks, of course you don't know what went wrong.
    If the open() fails, then perl will give you the right error. If
    "top" is failing and you want to capture the diagnostic (i.e. not just
    the wait() status) use IPC::Open3 to catch its stderr.

    --
    Steve
    Steve Grazzini, Sep 16, 2003
    #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. Replies:
    6
    Views:
    14,570
    Darryl L. Pierce
    Jan 1, 2006
  2. null7
    Replies:
    3
    Views:
    4,837
    Raymond DeCampo
    Jan 29, 2006
  3. Nik Coughin

    res:// protocol

    Nik Coughin, Jan 10, 2004, in forum: HTML
    Replies:
    6
    Views:
    4,997
    Nik Coughin
    Jan 12, 2004
  4. Leiradella, Andre V Matos Da Cunha

    RES: RES: Bare-bones Ruby

    Leiradella, Andre V Matos Da Cunha, Dec 29, 2004, in forum: Ruby
    Replies:
    1
    Views:
    289
    Stefan Schmiedl
    Dec 29, 2004
  5. Leiradella, Andre V Matos Da Cunha

    RES: RES: RES: Bare-bones Ruby

    Leiradella, Andre V Matos Da Cunha, Dec 29, 2004, in forum: Ruby
    Replies:
    0
    Views:
    125
    Leiradella, Andre V Matos Da Cunha
    Dec 29, 2004
Loading...

Share This Page