C#中怎么用process调用一个exe文件并传入参数?


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());
}

 

posted @ 2018-03-01 19:14  秋天的林子  阅读(17490)  评论(0编辑  收藏  举报