8

I'll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

0

1 Answer 1

19

Here is a script which does that. See Windows PowerShell Blog for the original example.

$p = [diagnostics.process]::start("notepad.exe")
if ( ! $p.WaitForExit(1000) ) 
  { echo "Notepad did not exit after 1000ms"; $p.kill() }
Sign up to request clarification or add additional context in comments.

1 Comment

On PowerShell 2.0 you can replace that first line with `$p = Start-Process Notepad -passthru'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.