你能从C#中的另一个应用程序中启动的进程中获得跟踪输出吗

本文关键字:跟踪 输出 进程 应用程序 另一个 启动 | 更新日期: 2023-09-27 18:01:11

我正在运行一个应用程序A,它使用进程启动来启动另一个应用软件B。我有可能得到应用程序B的跟踪信息吗?

你能从C#中的另一个应用程序中启动的进程中获得跟踪输出吗

您可以捕获StandardOutput。来自MSDN文档:

// Start the child process.
 Process p = new Process();
 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = "Write500Lines.exe";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();

因此,通过读取StandardOutput(和/或StandardError(,您可以捕获刚刚启动的进程的输出。