public void Can_Redirect_Stdout() { RedirectedProcess proc = new RedirectedProcess("cmd", "/c echo hi from stdout"); var lret = proc.Start(); Console.WriteLine("Exit code: {0}", lret.Item1); Console.WriteLine(lret.Item2); Assert.AreEqual("hi from stdout", lret.Item2.TrimEnd(Environment.NewLine.ToArray())); }
public void Can_Redirect_Large_Data() { using (var tmp = TempDir.Create()) { var txtfile = Path.Combine(tmp.Name, "test.text"); string [] lines = Enumerable.Range(0, 10000).Select(x => String.Format("Line {0}", x)).ToArray(); File.WriteAllLines(txtfile, lines); var type = new RedirectedProcess("cmd", String.Format("/C type {0}", txtfile)); var lret = type.Start(); Assert.AreEqual(String.Join(Environment.NewLine, lines), lret.Item2.TrimEnd(Environment.NewLine.ToCharArray())); } }
public static async Task ExecuteHardRemoval (String sourceVideoFileName, String outputFileName, IEnumerable <SubtitleParameters> subtitleParameters) { // AviSynth for x26x - Process source file using hard-coded subtitle removal algorithm String avsFileName = Path.Combine(Path.GetTempPath(), "HardCodedSubtitleRemoval.avs"); // For some reason avs4x26x program cannot accept input file name with # character String x264OutputFileName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(outputFileName).Replace("#", String.Empty) + ".264"); File.WriteAllText(avsFileName, SubtitleRemovalHelper.WriteHardCodedSubtitleRemovalAVS (sourceVideoFileName, ToolPaths.ToolsPath, subtitleParameters)); String arguments = $"-o \"{x264OutputFileName}\" \"{avsFileName}\""; using (RedirectedProcess process = new RedirectedProcess(ToolPaths.AVS4x26xPath, arguments)) { App.LogViewModel.RedirectedProcess = process; await process.StartAsync(); } File.Delete(avsFileName); // FFVideoSource produces .ffindex files in the same folder of the source file if (File.Exists(sourceVideoFileName + ".ffindex")) { File.Delete(sourceVideoFileName + ".ffindex"); } // MP4Box - Pack AviSynth output into video stream String videoOutputFileName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(outputFileName) + ".v"); arguments = $"-add \"{x264OutputFileName}\" \"{videoOutputFileName}\""; using (RedirectedProcess process = new RedirectedProcess(ToolPaths.MP4BoxPath, arguments)) { App.LogViewModel.RedirectedProcess = process; await process.StartAsync(); } File.Delete(x264OutputFileName); // FFProbe - Detect audio format of the source arguments = $"-v error -select_streams a:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1" + $" \"{sourceVideoFileName}\""; String audioFormat = null; using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFProbePath, arguments)) { await Task.Run(() => { process.Start(); audioFormat = process.StandardOutput.ReadToEnd().Trim(); process.WaitForExit(); }); } if (!String.IsNullOrEmpty(audioFormat)) { // FFMPEG - Extract audio stream String audioOutputFileName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(outputFileName) + $".{audioFormat}"); arguments = $"-i \"{sourceVideoFileName}\" -vn -acodec copy \"{audioOutputFileName}\""; using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath, arguments)) { App.LogViewModel.RedirectedProcess = process; await process.StartAsync(); } // FFMPEG - Remux audio stream with packed video stream arguments = $"-i \"{videoOutputFileName}\" -i \"{audioOutputFileName}\" -map 0:v -map 1:a -c copy -y" + $" \"{outputFileName}\""; using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath, arguments)) { App.LogViewModel.RedirectedProcess = process; await process.StartAsync(); } File.Delete(videoOutputFileName); File.Delete(audioOutputFileName); } else { throw new InvalidDataException("Unexpected audio format detection error occurred."); } }