ProcessStartInfo startInfo = new ProcessStartInfo("someExecutable.exe");
這是否實際運行someExecutable.exe
還是隻是監控?我基本上看到,如果這可以用來從已經運行的exe中讀取輸出,或者它會調用exe。
我想找到一種方法來監視和記錄已經運行的exe中的幾個值。
ProcessStartInfo startInfo = new ProcessStartInfo("someExecutable.exe");
這是否實際運行someExecutable.exe
還是隻是監控?我基本上看到,如果這可以用來從已經運行的exe中讀取輸出,或者它會調用exe。
我想找到一種方法來監視和記錄已經運行的exe中的幾個值。
這是真的運行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);
我知道的屬性,但我所問的是,如果我專門設置FileName屬性是否意味着它要運行exe? – user3174707
@ user3174707:** No ** - 設置FileName屬性不會運行exe!我添加了一個評論示例來澄清我的答案。 – pasty