Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a program from PowerShell with timeout

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.

like image 572
magol Avatar asked Nov 17 '09 09:11

magol


1 Answers

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() }
like image 200
Alexander Egger Avatar answered Oct 24 '22 10:10

Alexander Egger