windows - How to kill a process opened with open () -
i trying kill process opened in background in perl on win32 (xp) tried several things.... not seems working....
$pid = open( cmd, "| cmd.exe > c:\\cmdout.txt" );
to kill background process tried several things....:(
system('taskkill /f /im cmd.exe');
system("taskkill /f /pid $pid");
close cmd || warn "cmd exited $?";
option 2 never works tried print values of pid print , actual in system different. option 1 works feel process still running in ground because after end process wait time , re start process...
please
-thanks
i played bit case. apparently 2 cmd.exe started, parent pid returned open
, child doing commands.
second scenario partially works, kills parent, child remain running. using /t
option taskkill
can force kill children:
system("taskkill /f /t /pid $pid");
you see message termination of both processes:
success: process pid 3956 child of pid 1864 has been terminated. success: process pid 1864 child of pid 580 has been terminated.
third scenario seems work fine me. closing filehandle makes both cmd processes die.
Comments
Post a Comment