C#传参调用外部exe
string exePath = @"C:\demo\demo.exe";string dir = Path.GetDirectoryName(exePath);//exe所在文件夹,设置为工作目录string arguments = "--f abc"; //参数用空格分隔ProcessStartInfo startInfo = new ProcessStartInfo{FileName = exePath, // exe路径WorkingDirectory = dir, // 设置工作目录,有些外部exe用到相对路径时需要设置UseShellExecute = false,// 是否通过Windows Shell来启动外部exe目标进程Arguments = arguments //传参};// 启动进程Process process = new Process();process.StartInfo = startInfo;process.Start();process.WaitForExit(); // 等待程序结束Console.WriteLine($"程序退出码: {process.ExitCode}");
正常结束的程序退出码为:0