c程序怎麼執行?C#程序在某種情況下需要打開另外一個exe程序,下面介紹2種方式:,我來為大家科普一下關于c程序怎麼執行?以下内容希望對你有幫助!
C#程序在某種情況下需要打開另外一個exe程序,下面介紹2種方式:
方法一
string[] the_args = { "1","2","3","4"}; // 被調exe接受的參數
// 被調exe接受的參數,将參數拼接成字符串
string the_args = "";
foreach (string arg in args)
{
the_args = the_args arg " ";
}
the_args = the_args.Trim();
string exe_path = pict1.AccessibleName; // 被調exe的路徑
System.Diagnostics.Process.Start(exe_path, the_args);
方法二
// 調用exe的函數
using System.Diagnostics;
public bool StartProcess(string exe_path, params string[] args)
{
string s = "";
foreach (string arg in args)
{
s = s arg " ";
}
s = s.Trim();
Process process = new Process();//創建進程對象
ProcessStartInfo startInfo = new ProcessStartInfo(runFilePath, s); // 括号裡是(程序名,參數)
process.StartInfo = startInfo;
process.Start();
return true;
}
string exe_path = "E:/CIS.exe"; // 被調exe
string[] the_args = { "1","2","3","4"}; // 被調exe接受的參數
StartProcess(exe_path, the_args);
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!