2014-01-08 155 views
0

当你调用:processStartInfo运行exe?

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

这是否实际运行someExecutable.exe还是只是监控?我基本上看到,如果这可以用来从已经运行的exe中读取输出,或者它会调用exe。

我想找到一种方法来监视和记录已经运行的exe中的几个值。

回答

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); 
+0

我知道的属性,但我所问的是,如果我专门设置FileName属性是否意味着它要运行exe? – user3174707

+0

@ user3174707:** No ** - 设置FileName属性不会运行exe!我添加了一个评论示例来澄清我的答案。 – pasty