Search code examples
perlcygwintaskkill

Suppress prints from TASKKILL


I'm writing a Perl script that makes system calls to kill running processes. For instance, I want to kill all PuTTy windows. In order to do this, I have:

system('TASKKILL /F /IM putty* /T 2>nul');

For each process that's killed, however, I get a print saying

SUCCESS: The process with PID xxxx child of PID xxxx has been terminated.

which is cluttering my CLI. What's an easy way to eliminate these prints? Also note, that I'm executing these scripts in Cygwin.


Solution

  • Redirect sderr->stdout->nul:

    system('TASKKILL /F /IM putty* /T 1>nul 2>&1');
    

    or just simply grab output:

    my $res = `TASKKILL /F /IM putty* /T 2>nul`;