【源码】c#调用含参数exe文件,获取打印值

2025-04-13 07:38:52

1、1. c#如何用process调用exe文件(含参数)??参见我的经验如下,如何开启多线程请参加我的经验如下

【源码】c#调用含参数exe文件,获取打印值

2、2. testCallExe文件中Program.cs文件,添加代码如下所示namespace testCallExe{class Pro爿讥旌护gram{private static string[] ss = new string[10];static void Main(string[] args){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("---------开始了新线程---------");string cPath = ".\\..\\..\\..\\WebBrowserExe\\bin\\Debug\\";string cParams = ss[0];string filename = Path.Combine(cPath, "WebBrowserExe.exe");var proc = new Process{StartInfo = new ProcessStartInfo{FileName = filename,Arguments = cParams,UseShellExecute = false,RedirectStandardOutput = true,CreateNoWindow = true}};proc.Start();while (!proc.StandardOutput.EndOfStream){string line = proc.StandardOutput.ReadLine();// do something with lineConsole.WriteLine(line);}Thread.Sleep(4000);Console.WriteLine("---------关闭exe---------");//proc.CloseMainWindow();//proc.Close();//proc.WaitForExit();Console.WriteLine("---------线程结束---------");Console.ReadLine();}}}}

【源码】c#调用含参数exe文件,获取打印值

3、3. WebBrowsweExe中的Program.cs添加代码如下:namespace WebBrowserExe{class Program{static void Main(string[] args){if( args.Length <= 0){Application.Exit();}string href = args[0];Thread.Sleep(2000);Console.WriteLine(href + " 输出传入的参数");Console.ReadLine();}}}

【源码】c#调用含参数exe文件,获取打印值

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

【源码】c#调用含参数exe文件,获取打印值
【源码】c#调用含参数exe文件,获取打印值
【源码】c#调用含参数exe文件,获取打印值

5、5. 运行程序如下所示:从exe中获取到的输出值已经在控制台中打印出来了

【源码】c#调用含参数exe文件,获取打印值

6、6. 程序结束如下:图中显示的是线程已经结束。

【源码】c#调用含参数exe文件,获取打印值

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

【源码】c#调用含参数exe文件,获取打印值
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢