So I've been using Handbrake command line to encode my video collection to store on my NAS so I can use it on my HTPC. I was looking for a way to output both to the screen so I can watch it's output as it's encoding, but also to a file so I can go back and look at a particular encoding session.
My solution for this was to use one Powershell window to run the encoding and output to a file, then another Powershell window to read the log file and display it on screen. This works, but I want to improve it, as it's not perfect. Because the read file script reads at a set interval, it misses lines. Also if I reduce the interval, it has an effect on system performance, making the encoding run a bit slower. Is there a way I can redirect the output of the first window to both a file and to the screen?
The first powershell script (the one that starts the encoding) called "Convert1.ps1" (run from the handbrake install directory):
net time \\ODIN |find "Current time"
./HandbrakeCLI.exe -i "<input file>" -o "<output file>" <handbrake parameters>
The second powershell script to output to a file, called "Start_Convert.ps1":
d:\Conversions\Convert.ps1 2>&1 | out-file d:\Conversions\Completed\Movies\9.29.2010.log
The third powershell script to read from that log file, called "Watch_Output.ps1":
while (1)
{
(Get-Content d:\Conversions\Completed\Movies\9.29.2010.log)[-1]
Start-sleep 5
}
I'd like, ideally, to get this all down to one powershell window running a single script to start the encoding, output to a file, and display it on screen.
Edit (Adding Solution): 2 different ways to do it, I'm going with the latter since it is simpler.
Way #1 - Start-Job Resulting script to start my conversions:
Start-Job -Name VideoConvert -ScriptBlock { d:\Conversions\Convert.ps1 2>&1 | out-file d:\Conversions\Movies\Movie.log }
Get-FileTail -Wait Encoding Unicode -Path D:\Conversions\Completed\Movies\Movie.log
Way #2 - Tee-Object Resulting script to start my conversions:
d:\Conversions\Convert.ps1 2>&1 |Tee-Object -File D:\Conversions\Completed\Movies\Movie.log
Thanks again all. This works just like I wanted it to work.