(方法一)返回值为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();

最新文章

  1. EasyUI的使用
  2. 搭建Android开发环境。
  3. ife2015-task2
  4. Qweb Pdf 中添加 图片
  5. mysql连接查询语句示例
  6. android下asynchttp库对于session的支持
  7. Extmail maildrop错误
  8. UVA 1557 - Calendar Game(博弈dp)
  9. 从零搭建LNMP环境
  10. Qt同步线程(比较清楚,而且QMutex QMutexLocker QReadWriteLock QSemaphore QWaitCondition 每个都有例子)
  11. Android使用Activity用作弹出式对话框
  12. mybatis入门-动态sql
  13. 电商的噩梦?实体商家的福音——VR全景智慧城市
  14. TwenLite源码阅读
  15. 远程桌面服务当前正忙,因此无法完成您尝试执行的任务-win2008R2
  16. poj3259Wormholes (Bellman_Ford/SPFA/Floyed算法判断是否存在负环)
  17. flutter控件之ExpansionPanelList
  18. js图片预加载、有序加载
  19. 怎样让oracle实验本在不做实验时性能提升——win7下举例
  20. C++中的vector&find_if

热门文章

  1. windows核心编程 第5章job lab示例程序 解决小技巧
  2. Ansible配置详解
  3. 踩坑踩坑之Flask+ uWSGI + Tensorflow的Web服务部署
  4. MySQL系统表的利用姿势(浅探)
  5. .NetCore WebApi —— Swagger版本控制
  6. netty源码解解析(4.0)-24 ByteBuf基于内存池的内存管理
  7. 小游戏:200行python代码手写2048
  8. python编程基础之十一
  9. 【NOIP模拟赛】小奇挖矿 2
  10. python-Flask模版注入攻击SSTI(python沙盒逃逸)