惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
MongoDB | Blog
MongoDB | Blog
V
V2EX
博客园 - 【当耐特】
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
B
Blog
V
Visual Studio Blog
D
DataBreaches.Net
C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
F
Fortinet All Blogs

博客园 - 李瑞

HART通讯协议及应用 数据库连接 Web.Config C#访问接口 ObjectDataSource 用法1 ObjectDataSource用法 Machine.config 和 Web.config sql语句大全 仪表销售管理软件需求分析 女人爱男人的七种方式 结婚不是吸毒房子不是毒品 为何一定要买房? Windows2000里如何禁止网页修改注册表 怎样用C#实现完整文档打印功能 用visual c#获得计算机名称和ip地址 十四种系统故障的解决方法 C#入门教程(下) C#入门教程(中) C#入门教程(上) 清除Sqlserver数据库日志几种方法
C#程序调用外部程序
李瑞 · 2006-05-16 · via 博客园 - 李瑞

using  System;

class  test
{
static  void  Main()
{

//声明一个程序信息类
System.Diagnostics.ProcessStartInfo  Info  =  new  System.Diagnostics.ProcessStartInfo();

//设置外部程序名
Info.FileName  =  "notepad.exe";

//设置外部程序的启动参数(命令行参数)为test.txt
Info.Arguments  =  "test.txt";

//设置外部程序工作目录为  C:\
Info.WorkingDirectory  =  "C:\\";

//声明一个程序类
System.Diagnostics.Process  Proc  ;

try
{
//
//启动外部程序
//
Proc  =  System.Diagnostics.Process.Start(Info);
}
catch(System.ComponentModel.Win32Exception  e)
{
Console.WriteLine("系统找不到指定的程序文件。\r{0}",  e);
return;
}

//打印出外部程序的开始执行时间
Console.WriteLine("外部程序的开始执行时间:{0}",  Proc.StartTime);

//等待3秒钟
Proc.WaitForExit(3000);

//如果这个外部程序没有结束运行则对其强行终止
if(Proc.HasExited  ==  false)
{
Console.WriteLine("由主程序强行终止外部程序的运行!");
Proc.Kill();
}
else
{
Console.WriteLine("由外部程序正常退出!");
}
Console.WriteLine("外部程序的结束运行时间:{0}",  Proc.ExitTime);
Console.WriteLine("外部程序在结束运行时的返回值:{0}",  Proc.ExitCode);
}
}