Lucas Meijer
Lucas Meijer

Reputation: 4484

How can I kill a program that might not exist from Perl on Win32?

I'm looking for a way to make Perl kill all firefox.exe processes on Win32, and not give an error if no process exists. I'm currently using:

system('taskkill /F /IM firefox.exe');

which throws up a big "ERROR: No such process found", when firefox wasn't present.

Upvotes: 2

Views: 1260

Answers (3)

ghostdog74
ghostdog74

Reputation: 342273

without calling taskkill, you can use Perl modules, eg Win32::Process::List, win32::Process::Kill

See also perldoc -f kill

Upvotes: 3

tster
tster

Reputation: 18237

`taskkill /F /IM firefox.exe 2>&1`

Upvotes: 3

Scott Arrington
Scott Arrington

Reputation: 12503

If you want to suppress all output including errors, try this:

system('taskkill /F /IM firefox.exe >nul 2>&1');

You can see more information about command redirection and pipes here:

http://ss64.com/nt/syntax-redirection.html

Upvotes: 6

Related Questions