processStartInfo运行exe?

时间:2014-01-08 19:22:08

标签: monitoring processstartinfo

当你调用时:

ProcessStartInfo startInfo = new ProcessStartInfo("someExecutable.exe");

这实际上是运行someExecutable.exe还是只监控它?我基本上看到这是否可用于从已经运行的exe读取输出或是否将调用exe。

我正试图找到一种方法来监视和记录已经运行的exe中的一些值。

1 个答案:

答案 0 :(得分:0)

  

这实际上是运行someExecutable.exe还是死了只是监视它?

答案是既不是......也不是MSDN article about the ProcessStartInfo州:

  

您可以使用ProcessStartInfo类来更好地控制您启动的进程。您必须至少手动或使用构造函数设置FileName属性。

以及

  

ProcessStartInfo与Process组件一起使用。使用Process类启动进程时,除了附加到正在运行的进程时可用的进程信息外,还可以访问进程信息。

使用 ProcessStartInfo 类,您既不能启动也不能监控流程。

取决于您需要监控的内容(例如可执行文件的输出),您可以使用 ProcessStartInfo 类重定向您要进行的流程的输出以编程方式启动。为此,您需要设置 ProcessStartInfo 类的RedirectStandardOutput property。假设您将以编程方式启动进程,那么您需要该类以允许/配置进程监视。

评论的MSDN示例澄清了我的答案:

// Process is NOT started yet! process name is set
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
// Process is NOT started yet! process object is initialized with the process info like filename and so on. 
Process.Start(startInfo);
// Process is NOT started yet! process arguments are set. 
// The equivalent command line in a shell would be: c:\>IExplore.exe www.northwindtraders.com ENTER is NOT pressed yet!
startInfo.Arguments = "www.northwindtraders.com";
// NOW the process is executed/started => 
// c:\>IExplore.exe www.northwindtraders.com <= ENTER is pressed, process is started/running!
// c:\>
Process.Start(startInfo);