Arun090412 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Kindly let me know, how to check a windows application(for eg: notepad.exe, excel.exe) is already running using a perl script. Thanks in Advance!

Replies are listed 'Best First'.
Re: Window Process check
by BrowserUk (Patriarch) on Jun 22, 2012 at 13:55 UTC

    Simple way:

    C:\test>perl -E"say 'notepad is ', grep( /notepad/, `tasklist`) ? '' +: 'not ', 'running'" notepad is not running C:\test>start notepad.exe C:\test>perl -E"say 'notepad is ', grep( /notepad/, `tasklist`) ? '' +: 'not ', 'running'" notepad is running

    See Win32::Process::Info for another way.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: Window Process check
by maggotbrain (Monk) on Jun 24, 2012 at 01:44 UTC
    Here is one way to do it using the Win32::Process::Info module:
    use strict; use warnings; use Win32::Process::Info; my $pid = Win32::Process::Info->new (); my @info = $pid->GetProcInfo (); @info = grep { defined $_->{Name} && $_->{Name} =~ m/notepad/ } $pid->GetProcInfo (); # All processes with 'notepad' in name. for my $pid (@info){ print $pid->{"Name"}. " is running.\n"; }