Powershell tail log to console while process is running -
i have process sends output log file. want write powershell script start process, wait finish, , whilst running, tail log file 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
... , other similar arrangements, using jobs. looks output of jobs available either after job stopped, or sending 'events' it, sound they're not meant rapid things log messages (e.g. 100,000 lines in ~1 min).
is there other way this? next option call 'tail' start-process
, job done (i think - doesn't have same "wait stop" output behaviour), feels wrong.
job output isn't displayed unless retrieve job. why don't reverse you're doing: start process job, , tail log file on console:
$job = start-job -scriptblock { & "some_process.exe" } get-content "some_logfile.log" -wait
if want tail terminate when process terminates run both jobs, , retrieve output log job while other job running:
$pjob = start-job -scriptblock { & "some_process.exe" } $ljob = start-job -scriptblock { get-content "some_logfile.log" -wait } while ($pjob.state -eq 'running' -and $ljob.hasmoredata) { receive-job $ljob start-sleep -milliseconds 200 } receive-job $ljob stop-job $ljob remove-job $ljob remove-job $pjob
Comments
Post a Comment