Using Powershell 2.0 on the Windows 7 Desktop
I want to create a process to run the ant command, and then wait for this process to complete in a few minutes. If time and process still work, I want to kill him.
I wrote the code as below:
$p = Start-Process "cmd.exe" '/c ant execute' -PassThru -RedirectStandardOutput $log_file_path Wait-Process -id $p.ID -timeout 100 if(!$p.hasExited) { echo "kill the process" $p.Kill()
Although the process has not been killed, it still works even after executing the Start-Sleep instruction.
I also tried using the Stop-Process command, as the commented line indicates that no luck, the process is still running.
Perhaps I missed something important, give me the key.
EDIT:
It turns out that in the cmd window, the child processes are still running, kill only the cmd process.
Finally, I did the work with the following code:
if(!$p.hasExited) { echo "kill the process" taskkill /T /F /PID $p.ID
source share