I have a process which sends output to a log file. I want to write a Powershell script to start this process, wait for it to finish, and whilst it is running, tail its log file to the console in real time.
I have tried this:
$procs = Start-Process "some_process.exe"
$logjob = Start-Job -Arg "some_logfile.log" -ScriptBlock {
param($file)
Get-Content $file -wait | foreach { Write-Host($_) }
}
$procs | Wait-Process
$logjob | Stop-Job
... and other similar arrangements, using jobs. But it looks like the output of jobs is only available either after the job is stopped, or by sending 'events' from it, which sound like they're not really meant for rapid things like log messages (e.g. 100,000 lines in ~1 min).
Is there some other way to do this? My next option is to just call 'tail' from Start-Process
, which would get the job done (I think - hopefully this doesn't have the same "wait for stop" output behaviour), but feels wrong.