Tag: redirectstandardoutput

为什么在使用控制台应用程序测试时,在dll中启动进程,而在另一个dll调用时却没有?

上周我发布了这个问题: 如何在C#dll中将其作为一个进程运行时获取控制台应用程序输出,因为我试图找出问题的原因。 但是,我一直无法找到我收到错误的原因所以我想我会要求跟进直接解决我遇到的问题。 我正在研究DLL中的方法,我必须在其中启动一个进程。 用于执行此操作的代码是: ProcessStartInfo psi = new ProcessStartInfo(); psi.UseShellExecute = false; psi.ErrorDialog = false; psi.RedirectStandardError = true; psi.RedirectStandardOutput = true; psi.RedirectStandardInput = true; psi.CreateNoWindow = true; psi.FileName = @”C:\Program Files\OpenMS-1.6\XTandemAdapter.exe”; psi.Arguments = @”-ini C:\XTandemAdapter.ini”; Process getIDs = new Process(); getIDs.StartInfo = psi; getIDs.Start(); StreamWriter inputWriter = getIDs.StandardInput; StreamReader outputReader = getIDs.StandardOutput; StreamReader errorReader […]

来自C#应用程序的ffmpeg使用Process类 – 用户提示符未显示在standardError中

我正在编写一个使用c#运行ffmpeg的应用程序。 我的程序将standardError输出重定向到流,以便可以解析它以获取进度信息。 在测试期间,我发现了一个问题: 如果输出显示在命令窗口而不是被重定向,则ffmpeg将显示它的正常标题,后跟“file c:\ temp \ testfile.mpg已经存在.overrite [y]” 。 如果我单击命令窗口并按y,程序将继续对文件进行编码。 如果将StandardError重定向到我的处理程序然后打印到控制台,我会看到现在打印到控制台的命令窗口中显示的相同标题信息。 除了文件……已存在提示 。 如果我在命令窗口中单击并按y,程序将继续处理该文件。 当提示操作员提供信息时,是否存在除standardOutput或standardError之外的流,或者我是否遗漏了其他内容? public void EncodeVideoWithProgress(string filename, string arguments, BackgroundWorker worker, DoWorkEventArgs e) { Process proc = new Process(); proc.StartInfo.FileName = “ffmpeg”; proc.StartInfo.Arguments = “-i ” + ” \”” + filename + “\” ” + arguments; proc.StartInfo.UseShellExecute = false; proc.EnableRaisingEvents = true; […]

在单个控制台行上处理输出重定向

我正在编写一个C#应用程序,它可以启动第三方命令行可执行文件并将其标准输出重定向到RichTextBox。 我可以使用process.OutputDataReceived事件重定向输出。 我有一个我推送行的队列,然后我使用一个计时器定期将所有排队的行转储到RichTextBox中。 这适用于某些第三方程序。 问题在于多次向控制台的单行写入的程序。 例如:5% – > 10% – > 25%等…(不断重写相同的位置)我想,这是通过不放置换行符来完成的,而是简单地返回到行的开头回车并写回以前的字符。 会发生什么是OutputDataReceived似乎没有任何方式来指示是否应该应用新行,所以我的RichTextBox输出只是在新行上有多个更新。 例如:5%10%25%等… 有没有办法判断标准输出是在新线还是在同一条线上?

重定向进程输出C#

我想将Process的标准输出重定向到一个字符串,以便以后解析。 我还希望在进程运行时看到屏幕上的输出,而不仅仅是当它完成运行时。 这有可能吗?

从控制台应用程序发送输入/获取输出(C#/ WinForms)

我有一个包含3个控件的表单: 用户输入命令以发送到控制台应用程序的文本框, 用于确认要发送的命令的按钮 一个只读文本框,用于显示应用程序的输出。 我想要的是让用户在第一个文本框中输入命令,按下按钮以通过第二个文本框输入和接收反馈。 我知道如何使用ProcessStartInfo.RedirectStandardOutput但是,当我使用StandardOutput.ReadToEnd()时,应用程序挂起。 我看了一下异步的Process.BeginOutputReadLine()但是,即使我的应用程序没有挂起,不知何故我在文本框中没有得到任何响应,它什么也没做。 这是我的代码: public partial class MainForm : Form { private void MainForm_Load(object sender, EventArgs e) { InitializeInterpreter(); } private void InitializeInterpreter() { InterProc.StartInfo.UseShellExecute = false; InterProc.StartInfo.FileName = “app.exe”; InterProc.StartInfo.RedirectStandardInput = true; InterProc.StartInfo.RedirectStandardOutput = true; InterProc.StartInfo.RedirectStandardError = true; InterProc.StartInfo.CreateNoWindow = true; InterProc.OutputDataReceived += new DataReceivedEventHandler(InterProcOutputHandler); InterProc.Start(); } private static void […]

C#运行时获取进程输出

无论如何,重定向生成的进程的标准输出并将其捕获为它的发生。 我看到的所有内容在完成后都会执行ReadToEnd。 我希望能够在打印时获得输出。 编辑: private void ConvertToMPEG() { // Start the child process. Process p = new Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; //Setup filename and arguments p.StartInfo.Arguments = String.Format(“-y -i \”{0}\” -target ntsc-dvd -sameq -s 720×480 \”{1}\””, tempDir + “out.avi”, tempDir + “out.mpg”); p.StartInfo.FileName […]

ProcessInfo和RedirectStandardOutput

我有一个应用程序在命令窗口中调用另一个进程,该进程已更新输出到控制台窗口的统计信息。 我认为这是一个相当简单的操作,但我似乎无法让它工作。 我错过了什么吗? string assemblyLocation = Assembly.GetExecutingAssembly().Location; Process process = new Process { ProcessStart = { RedirectStandardOutput = true, UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, Arguments = arg, FileName = assemblyLocation.Substring(0, assemblyLocation.LastIndexOf(“\\”)) + “\\ffmpeg.exe”, CreateNoWindow = true } }; process.Start(); Console.WriteLine(process.StandardOutput.ReadToEnd()); process.WaitForExit(); 理想情况下,我想要的是输出在我触及的过程中发生变化,或者数据进入读者,我从中得到了事件。 任何帮助都会很棒,我觉得这是一个新手问题,但似乎缺少一些东西。