Process类调用exe,返回值以及参数空格问题
2024-09-01 00:24:33
(方法一)返回值为int
fileName为调用的exe路径,入口参数为para,其中多个参数用空格分开,当D:/DD.exe返回值为int类型时。
Process p = new Process(); string fileName = @"D:/DD.exe"; string para ="aa bb"; ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName, para); p.StartInfo = myProcessStartInfo; p.Start(); while (!p.HasExited) { p.WaitForExit(); } int returnValue = p.ExitCode;
(方法二)返回值位string
返回值为string时,首先在生成DD.exe时主函数main返回值为void,但在主函数要用Write输出string,通过StandardOutput.ReadToEnd()获取输出流(即输出的字符串)
string fileName = @"D:/DD.exe"; Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = fileName; p.StartInfo.CreateNoWindow = true; p.StartInfo.Arguments = "aa bb cc";//参数以空格分隔 p.Start(); p.WaitForExit(); string output = p.StandardOutput.ReadToEnd();
p.Dispose();
p.Close();
PS:
1 、在输入参数 p.StartInfo.Arguments时,由于是以空格分隔,所以,当参数中含有字符串时,会强行分隔。比如我的入口参数需要以下四个参数:“D:\\Demo\\picWorldCup\\worldCup_cy.png” “Canon MG3600 series Printer XPS” “330” “471”,如果我直接写成如下形式(即直接用空格连接起来)p.StartInfo.Arguments=“D:\\Demo\\picWorldCup\\worldCup_cy.png Canon MG3600 series Printer XPS 330 471显然是不可以的,此时应该通过转义字符\"把属于一个参数的内容包含起来即可,如
p.StartInfo.Arguments = "\"D:\\Demo\\picWorldCup\\worldCup_cy.png\" \"Canon MG3600 series Printer XPS\" 330 471";
2 、如果不想弹窗, 除了设置p.StartInfo.CreateNoWindow = true;外还要p.Close();
最新文章
- EasyUI的使用
- 搭建Android开发环境。
- ife2015-task2
- Qweb Pdf 中添加 图片
- mysql连接查询语句示例
- android下asynchttp库对于session的支持
- Extmail maildrop错误
- UVA 1557 - Calendar Game(博弈dp)
- 从零搭建LNMP环境
- Qt同步线程(比较清楚,而且QMutex QMutexLocker QReadWriteLock QSemaphore QWaitCondition 每个都有例子)
- Android使用Activity用作弹出式对话框
- mybatis入门-动态sql
- 电商的噩梦?实体商家的福音——VR全景智慧城市
- TwenLite源码阅读
- 远程桌面服务当前正忙,因此无法完成您尝试执行的任务-win2008R2
- poj3259Wormholes (Bellman_Ford/SPFA/Floyed算法判断是否存在负环)
- flutter控件之ExpansionPanelList
- js图片预加载、有序加载
- 怎样让oracle实验本在不做实验时性能提升——win7下举例
- C++中的vector&;find_if
热门文章
- windows核心编程 第5章job lab示例程序 解决小技巧
- Ansible配置详解
- 踩坑踩坑之Flask+ uWSGI + Tensorflow的Web服务部署
- MySQL系统表的利用姿势(浅探)
- .NetCore WebApi —— Swagger版本控制
- netty源码解解析(4.0)-24 ByteBuf基于内存池的内存管理
- 小游戏:200行python代码手写2048
- python编程基础之十一
- 【NOIP模拟赛】小奇挖矿 2
- python-Flask模版注入攻击SSTI(python沙盒逃逸)