CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Getting output of PS command in script


New User

Jul 27, 2003, 5:12 PM

Post #1 of 2 (276 views)
Getting output of PS command in script Can't Post

I have been trying to find out how many copies of a script are running on the server, so that I don't overload it.

I am trying to use the PS command in my script. It runs, but all I get is a ret code of success (0), not the output

In an ls command the output is returned.

Here is some of the code I have tried

I get a retcode of 0 which indicates success. What I want is the same info that is printed when I run the command via telnet.

Is this possible?

#$parms = '-aef|grep birdsnw'; tried this first

$parms = '-aef';

$result = @stuff = `ps $parms`;

print "<hr>";

print "result - $result<br>\n";

if (@stuff) {

print "<pre>\n";

foreach $stuff (@stuff){

$stuff =~ s/\n/<br>/g;

print "$stuff";


print "</pre>\n";


else {

print "\@stuff is empty<br>\n";


print "<hr><p>\n";

Thaumaturge / Moderator

Jul 28, 2003, 1:49 AM

Post #2 of 2 (275 views)
Re: [CarolH] Getting output of PS command in script [In reply to] Can't Post

Looks like you're doing the right thing.

Note that $result won't hold the return code, it will contain the number of rows returned by "ps". If that's zero then it seems that your "ps" command isn't working properly. Are you sure that "ps" works on your computer?

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives