Skip to content

Instantly share code, notes, and snippets.

@shauvik
Created August 16, 2011 22:02
Show Gist options
  • Save shauvik/6d701adedbfd85be74b0 to your computer and use it in GitHub Desktop.
Save shauvik/6d701adedbfd85be74b0 to your computer and use it in GitHub Desktop.
Windows power shell run commands with timeout
$array = "folder1", "folder2"
cd c:\experiments
Foreach ($element in $array) {echo "Processing $element"; `
$p = $(Start-Process java -ArgumentList "-jar script.jar $element" -RedirectStandardOutput $element\out.log -RedirectStandardError $element\err.log -PassThru);`
if ( ! $p.WaitForExit(1800000) )
{ echo "$element did not exit after 30min"; $p.kill() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment