// This snippet needs the "System.Diagnostics"
// library
// Application path and command line arguments
string ApplicationPath = "C://example.exe";
string ApplicationArguments = "-c -x";
// Create a new process object
Process ProcessObj = new Process();
// StartInfo contains the startup information of
// the new process
ProcessObj.StartInfo.FileName = ApplicationPath;
ProcessObj.StartInfo.Arguments = ApplicationArguments;
// These two optional flags ensure that no DOS window
// appears
ProcessObj.StartInfo.UseShellExecute = false;
ProcessObj.StartInfo.CreateNoWindow = true;
// If this option is set the DOS window appears again
// ProcessObj.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
// This ensures that you get the output from the DOS application
ProcessObj.StartInfo.RedirectStandardOutput = true;
// Start the process
ProcessObj.Start();
// Wait that the process exits
ProcessObj.WaitForExit();
// Now read the output of the DOS application
string Result = ProcessObj.StandardOutput.ReadToEnd();
C# Run a console application without Window
最新推荐文章于 2022-03-21 16:04:24 发布
本文介绍如何使用C#通过Process类启动外部应用程序,并获取其输出。具体包括设置应用程序路径、命令行参数,以及如何配置ProcessStartInfo来避免显示命令窗口并重定向标准输出。
2722

被折叠的 条评论
为什么被折叠?



