开发者

What is the equivalent of ps command in perl?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜