C#程序执行EXE文件(调用Delphi)
2008年07月15日 星期二 下午 12:15
C#程序作为调用这需要生成一个Progress类,该类提供了调用EXE可执行文件所用到的属性和事件.
System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process();
pExecuteEXE.StartInfo.FileName = @"E:\Delphi.exe";
pExecuteEXE.StartInfo.Arguments = "'paramstr1 paramstr2,paramstr3'";
pExecuteEXE.Start();
pExecuteEXE.WaitForExit();//无限期等待完成
//pExecuteEXE.WaitForExit(10000);//等待最长10秒钟完成。Delphi可执行程序作为被调用程序,主要是接收参数信息,执行程序,由于程序执行程序完毕不能返回给调用程序信息,只能将信息写入某一位置等待调用者读取。
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
self.Caption :='';
for i:=0 to paramcount do
begin
self.Caption :=self.Caption+ '['+inttostr(i)+':'+paramstr(i)+']';
end;
end;
完成后退出。
这里是一个简单的调用例子,可以效仿:
* 功 能:通过C#程序调用 Windows 记事本程序 编辑一个
* 名为 test.txt 的文本文件。
*
* 在整个程序中 System.Diagnostics.Process.Start(Info)
* 为主要语句。
* 如果只是单独执行一个外部程序,可用一条如下代码即可:
* System.Diagnostics.Process.Start(
* "外部程序名","启动参数");
*/
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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
C#程序执行EXE文件(调用Delphi) 并传参
共20个文件
cs:6个
exe:3个
pdb:2个
4星 · 超过85%的资源 需积分: 47 48 下载量 37 浏览量
2011-10-26
10:41:28
上传
评论
收藏 220KB RAR 举报
温馨提示
C#程序作为调用这需要生成一个Progress类,该类提供了调用EXE可执行文件所用到的属性和事件. System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process(); pExecuteEXE.StartInfo.FileName = @"E:\Delphi.exe"; pExecuteEXE.StartInfo.Arguments = "'paramstr1 paramstr2,paramstr3'"; pExecuteEXE.Start(); pExecuteEXE.WaitForExit();//无限期等待完成 //pExecuteEXE.WaitForExit(10000);//等待最长10秒钟完成。 Delphi procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin self.Caption :=''; for i:=0 to paramcount do begin self.Caption :=self.Caption+ '['+inttostr(i)+':'+paramstr(i)+']'; end; end;
资源推荐
资源详情
资源评论
收起资源包目录
C#程序执行EXE文件(调用Delphi) .rar (20个子文件)
WindowsFormsApplication9
Form1.Designer.cs 1KB
Program.cs 505B
obj
Debug
WindowsFormsApplication9.exe 8KB
WindowsFormsApplication9.csproj.FileListAbsolute.txt 1KB
TempPE
WindowsFormsApplication9.Properties.Resources.resources 180B
WindowsFormsApplication9.csproj.GenerateResource.Cache 789B
WindowsFormsApplication9.pdb 24KB
bin
Debug
WindowsFormsApplication9.exe 8KB
WindowsFormsApplication9.vshost.exe.manifest 490B
WindowsFormsApplication9.pdb 24KB
WindowsFormsApplication9.vshost.exe 14KB
Form1.cs 826B
WindowsFormsApplication9.csproj 4KB
Properties
AssemblyInfo.cs 1KB
Settings.Designer.cs 1KB
Resources.resx 5KB
Settings.settings 249B
Resources.Designer.cs 3KB
Projects.rar 191KB
C#程序执行EXE文件(调用Delphi).txt 2KB
共 20 条
- 1
资源评论
- qqgoonqq2013-04-16要5分本来以为多好 但是太简单了 大众的方法一查都能知道还要5分
- lee0832013-09-12代码很简单,暂时没有用到
- gai245024762012-11-30代码很简单。
mayongtao520
- 粉丝: 62
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功