I'm having a very difficult time inspecting the $return variable. The print "return = ". $return ."\n"; always comes back blank even though the process is still running. I do receive a warning about uninitialized variable. Can someone please explain?
my $process="MInstaller";
my $return=` ps -eaf |grep $process | grep -v grep`;
sub chk_proc{
print "in chk_proc\n";
print "\n";
print "return = ". $return ."\n";
while ( my $return ne "" ) {
sleep(5);
};
};
You're close. Your code doesn't works, because the variable $return in the
while ( my $return ne "" ) {
is another variable (declared in the scope of while) as your first $return.
You can try the next:
use 5.014;
use warnings;
chk_proc('[M]Installer'); #use the [] trick to avoid the 'grep -v grep :)
sub chk_proc{ while( qx(ps -eaf |grep $_[0]) ) {sleep 5} };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With