I am using ps -C <executable name>
o开发者_JS百科n Linux, but the same does not work on Windows.
How can I perform the same check in Perl so that it is platform independent?
You might be able to use Win32::Process::List
use 5.12.0;
use warnings;
use Win32::Process::List;
my $P = Win32::Process::List->new();
if($P->IsError == 1) {
die $P->GetErrorText;
}
my %list = $P->GetProcesses();
foreach my $key (keys %list) {
# $list{$key} = process name, $key=PID
say sprintf("%25s %10s", $list{$key}, $key);
}
And process appropriately.
精彩评论