Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TailFile-UntilProcessStops {
- Param ($processID, $filePath)
- $loopBlock = {
- Param($filePath) Get-Content $filePath -Wait -Tail 0
- }
- $TailLoopJob = Start-Job -scriptBlock $loopBlock -ArgumentList $filePath
- try {
- do {
- $TailLoopJob | Receive-Job
- try {
- Wait-Process -id $processID -ErrorAction Stop -Timeout 1
- $waitMore = $false
- } catch {
- $waitMore = $true
- }
- } while ($waitMore)
- } finally {
- Stop-Job $TailLoopJob
- Remove-Job $TailLoopJob
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement