Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > open (RES, "/usr/bin/top -bs -n 1 |");

Reply
Thread Tools

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

 
 
Sandrine CHEN
Guest
Posts: n/a
 
      09-16-2003
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>";
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      09-16-2003
Sandrine CHEN <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Steve Grazzini
Guest
Posts: n/a
 
      09-16-2003
Sandrine CHEN <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
C# code needed to open the windows "Open with" dialog Shilpa ASP .Net 1 03-22-2006 12:17 PM
How to Redirect to Another Already Open Page (Managing Multiple Open Pages in ASP.Net) TC ASP .Net 3 12-07-2004 07:10 AM
Why cannot open .txt file with Encoding = UNICODE using javascript window.open()? ml Java 0 11-30-2004 07:43 AM
How do I open a database connection on an access file that currently open ? THY ASP .Net 4 08-22-2003 03:50 PM



Advertisments