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

推荐订阅源

博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
罗磊的独立博客
The GitHub Blog
The GitHub Blog
L
LangChain Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
DataBreaches.Net
宝玉的分享
宝玉的分享
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
美团技术团队
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog

博客园 - 李瑞

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);
}
}