1. 程式人生 > >C#中怎麽用process調用一個exe文件並傳入參數?

C#中怎麽用process調用一個exe文件並傳入參數?

[1] s參數 div tex 入參 orm ring gpo 轉換


System.Diagnostics.Process.Start("程序的路徑", "參數1 參數2");
第一個參數是aaa.exe 的路徑,第二個參數是用空格分開的兩個參數組成的字符串。
aaa.exe中的main方法寫做
static void Main(string[] args)
用Process.Start啟動aaa.exe時main方法的args參數就是Process.Start傳入參數用轉換成的長度為2的數組

代碼如下 調exe的寫法:

static void Main(string[] args)
{
System.Diagnostics.Process.Start(@"E:\SouceCode\WindowsFormsApplication1 - 副本\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe", "參數1 參數2");
}

被調的寫法:

static void Main(string[] args)
{
if (args.Length > 0)
{
string canshu1 = args[0];
string canshu2 = args[1];
MessageBox.Show(canshu1);
MessageBox.Show(canshu2);
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}

C#中怎麽用process調用一個exe文件並傳入參數?