我需要从我的 C# 应用程序启动一个 exe 文件。
查询字符串应如下所示:
Extractor.exe "base\sql" "develop" "..\Data\System" "Grids"
这是我的代码:
public static void StartExtractor()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = OurFields.keskullPass + @"\Extractor.Deploy\Extractor.exe";
process.StartInfo.Arguments = "\"base\\sql\" \"develop\" \"..\\Data\\System\" \"Grids\"";
process.Start();
process.WaitForExit();
}
最佳答案
在 C# 中使用参数启动进程的简单方法:
Process.Start("yourapp.exe", "your arguments");
如果你确实需要等待进程退出,那么它就会变成:
var process = Process.Start("yourapp.exe", "your arguments");
process.WaitForExit();
通常您不会手动创建 Process
对象。
进程在System.Diagnostics
中定义,因此您还需要将其添加到您的using子句中。
您的问题可能与外部应用程序对参数格式的特定期望有关,或者与 exe 完整路径的连接错误有关。
要引用参数,您可以像以前一样手动执行,或者使用类似的例程:How to correctly escape command line arguments in c#
有关如何启动进程的更多示例:
- How do I start a process from C#?
- Wait till a process ends
- Passing quotes in Process.Start arguments
- MSDN: Process.Start Method
- Microsoft: How to wait for a shelled application to finish by using Visual C# (also has an example on how to wait for process to complete with timeout)
关于c# - 如何在 C# 中使用参数启动 .exe 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35111168/