Computing.Net > Forums > Programming > Perl Win32::Process::Info

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl Win32::Process::Info

Reply to Message Icon

Name: Legum
Date: April 24, 2007 at 20:40:08 Pacific
OS: 2003
CPU/Ram: 1
Comment:

Iam trying to run a script quering some partucular service is running or not, if not running, restart the service., but I am getting error like " Unrecognized character \x94 "
my script is

process.pl
###############
use warnings;
use strict;

use Win32::Process::Info;

$check=$ARGV[0];
$running=0;
my $pi = Win32::Process::Info->new ();
foreach $proc ($pi->GetProcInfo ())
{
foreach (sort keys %$proc)
{
$proc= $proc->{$_};
if ($proc =~ /$check/)
{
$running=1;
}
}
}

if ($running==0)
{
$command=”net start $check”;
system($command);
}
###############

when I am running the process.pl with parameter lanmanserver, getting the error.

I will appriciate any help



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: April 24, 2007 at 22:16:10 Pacific
Reply:

First problem is that your code won't compile because you haven't declared your vars with the my keyword.

Second problem is that you're redefining $proc. In the outer loop, it's a hash reference, but then in the inner loop, you redefine it to be a scalar. You should use a different var name for the inner loop.

Are you using an IDE?

The " Unrecognized character \x94 " error message is most likely due to the ” ” in:
$command=”net start $check”;

Perl may not be "seeing" them as double quotes " ".


0

Response Number 2
Name: FishMonger
Date: April 24, 2007 at 22:42:35 Pacific
Reply:

See if this is closer to what you need.
=============================================
use warnings;
use strict;
use Win32::Process::Info;

my $check=$ARGV[0] || die "missing input arg";
my $running;
my $pi = Win32::Process::Info->new;

foreach my $proc ($pi->GetProcInfo)
{
if ($proc->{Name} =~ /$check/i )
{
$running++ and last;
}
}

system("net start $check") if ! $running;


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Params Property Greyed Ou... How to break/exit FOR /F ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Perl Win32::Process::Info

PERL 'Win32::Service' www.computing.net/answers/programming/perl-win32service-/14833.html

Perl: local IP info w/o knowing www.computing.net/answers/programming/perl-local-ip-info-wo-knowing/3953.html

Batch program in Perl needed www.computing.net/answers/programming/batch-program-in-perl-needed/13724.html