如何将手刹输出输出到屏幕和文件? [英] How can I output Handbrake output to both the screen and to a file?
问题描述
因此,我一直在使用Handbrake命令行对要存储在NAS上的视频集进行编码,以便可以在HTPC上使用它.我一直在寻找一种既可以将其输出到屏幕上的方式,以便可以在编码时看到它的输出,也可以将其输出到一个文件中,以便可以回头查看特定的编码会话.
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.
为此,我的解决方案是使用一个Powershell窗口运行编码并输出到文件,然后使用另一个Powershell窗口读取日志文件并将其显示在屏幕上.这行得通,但是我想改进它,因为它并不完美.由于读取文件脚本以设定的时间间隔读取,因此会丢失行.同样,如果减小间隔,则会影响系统性能,从而使编码运行速度变慢.有什么方法可以将第一个窗口的输出重定向到文件和屏幕上?
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?
第一个Powershell脚本(开始编码的脚本)称为"Convert1.ps1"(从手刹安装目录运行):
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>
第二个Powershell脚本输出到名为"Start_Convert.ps1"的文件:
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
要从该日志文件读取的第三个Powershell脚本,称为"Watch_Output.ps1":
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
}
理想情况下,我希望将其全部放到一个Powershell窗口中,该窗口运行一个脚本来开始编码,输出到文件并在屏幕上显示.
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.
编辑(添加解决方案): 这样做有2种不同的方法,我会选择后者,因为它更简单.
Edit (Adding Solution): 2 different ways to do it, I'm going with the latter since it is simpler.
方法#1-开始工作 启动我的转换的结果脚本:
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
方法#2-Tee对象 启动我的转换的结果脚本:
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.
推荐答案
我将为此使用Tee-Object:
I would use Tee-Object for this:
./HandbrakeCLI.exe -i infile -o outfile ... 2>&1 | Tee-Object -File movie.log
添加了2>&1
以将错误捕获到日志以及屏幕中.
Added in the 2>&1
to capture errors to the log as well as the screen.
这篇关于如何将手刹输出输出到屏幕和文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!