Windows运行进程列表perl

Windows运行进程列表perl,perl,process,monitor,Perl,Process,Monitor,我正在寻找获取Windows计算机上运行的进程(和服务)列表的最标准方法。不要使用“现代”东西很重要,因为我会在旧服务器上部署该程序 有什么想法吗?正如skp提到的,tasklist命令可以做到这一点(在Windows XP上测试) 下面是一个通过PID创建进程哈希的小脚本: use warnings; use strict; my @procs = `tasklist`; #Find position of PID based on the ===== ====== line in the

我正在寻找获取Windows计算机上运行的进程(和服务)列表的最标准方法。不要使用“现代”东西很重要,因为我会在旧服务器上部署该程序


有什么想法吗?

正如skp提到的,tasklist命令可以做到这一点(在Windows XP上测试)

下面是一个通过PID创建进程哈希的小脚本:

use warnings;
use strict;

my @procs = `tasklist`;

#Find position of PID based on the ===== ====== line in the header
my $pid_pos;
if ($procs[2] =~ /^=+/)
{
    $pid_pos = $+[0]+1;
}
else
{
    die "Unexpected format!";   
}

my %pids;
for (@procs[3 .. $#procs])
{
    #Get process name and strip whitespace
    my $name = substr $_,0,$pid_pos;
    $name =~s/^\s+|\s+$//g;

    #Get PID
    if (substr($_,$pid_pos) =~ /^\s*(\d+)/)
    {
        $pids{$1} = $name;  
    }
}

use Data::Dumper;
print Dumper %pids;

另一种可能有用的方法是。它使用核心WindowsC函数获取进程列表。它似乎适用于旧版本的Perl。

正如skp所提到的,tasklist命令可以做到这一点(在Windows XP上测试)

下面是一个通过PID创建进程哈希的小脚本:

use warnings;
use strict;

my @procs = `tasklist`;

#Find position of PID based on the ===== ====== line in the header
my $pid_pos;
if ($procs[2] =~ /^=+/)
{
    $pid_pos = $+[0]+1;
}
else
{
    die "Unexpected format!";   
}

my %pids;
for (@procs[3 .. $#procs])
{
    #Get process name and strip whitespace
    my $name = substr $_,0,$pid_pos;
    $name =~s/^\s+|\s+$//g;

    #Get PID
    if (substr($_,$pid_pos) =~ /^\s*(\d+)/)
    {
        $pids{$1} = $name;  
    }
}

use Data::Dumper;
print Dumper %pids;

另一种可能有用的方法是。它使用核心WindowsC函数获取进程列表。它似乎适用于旧版本的Perl这是过时的吗?它在Windows上工作吗?我的坏!没有看到“Windows”。我认为tasklist实际上可以做到这一点
my$process=`ps`这是过时的吗?它在Windows上工作吗?我的坏!没有看到“Windows”。我认为任务列表将实际执行此操作