Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 isprocess.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

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 " ".

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;

![]() |
Params Property Greyed Ou...
|
How to break/exit FOR /F ...
|

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