【源码】c#如何用process调用exe文件(含参数)
1、1. 打开vs,创建两个工程如下图所示(解决方案如何添加新项目,见我的经验如下)。其中WebBrowsweExe生成exe文件,testCallExe用来调用exe文件。

2、2. testCallExe文件中Program.cs文件,添加代码如下所示
namespace testCallExe
{
class Program
{
private static string[] ss = new string[10];
static void Main(string[] args)
{
//string[] ss = new string[10];
ss[0] = "jingyan.baidu.com/article/90808022090decfd91c80f8e.html";
ThreadStart threadStart = new ThreadStart(startThread);
var thread = new Thread(threadStart);
thread.Start();//开始线程
}
private static void startThread()
{
Console.WriteLine("---------开始了新线程---------");
//Thread.Sleep(2000);//wait
string cPath = ".\\..\\..\\..\\WebBrowserExe\\bin\\Debug\\"
string cParams = ss[0];
string filename = Path.Combine(cPath, "WebBrowserExe.exe");
var proc = System.Diagnostics.Process.Start(filename, cParams);
Thread.Sleep(4000);
//
Console.WriteLine("---------关闭exe---------");
proc.CloseMainWindow();
proc.Close();
Console.WriteLine("---------线程结束---------");
Console.ReadLine();
}
}
}

3、3. WebBrowsweExe中的Program.cs添加代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WebBrowserExe
{
class Program
{
static void Main(string[] args)
{
if( args.Length <= 0)
{
MessageBox.Show("请输入启动参数");
Application.Exit();
}
string href = args[0];
Thread.Sleep(2000);
Console.WriteLine(href + " 输出传入的参数");
Console.ReadLine();
}
}
}

4、4. WebBrowsweExe生成exe,如下图所示



5、5. 运行程序截图如下:

6、6. 程序结束如下:

7、如果您觉得有用,记得在下方点击投票、点赞、关注、留言,小编会定期奉上更多的惊喜哦,您的支持才是小编继续努力的动力,么么哒。
