tags:

views:

177

answers:

3

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.

+3  A: 
`taskkill /F /IM firefox.exe 2>&1`
tster
This creates a (possibly empty) file called `1` in the current directory.
mobrule
slight typo here. you have the right idea, but if you just want to redirect error output, it should be `2>nul` instead of `2>1`
Scott Anderson
ephemient
Yes, I forgot the ampersand.
tster
+5  A: 

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

Scott Anderson
Does that work with Internet Explorer too? ;-)
Chris Huang-Leaver
yeah, just change the `firefox.exe` to `iexplore.exe`
Scott Anderson
+3  A: 

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

See also perldoc -f kill

ghostdog74