博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
外部程序用process.start调用 其它exe文件时可以传入参数.
阅读量:4041 次
发布时间:2019-05-24

本文共 990 字,大约阅读时间需要 3 分钟。

  1. 调用方的程序调用代码:

Process.Start(string exePathAndName, string parameter);

  1. 被调用 方 接收参数
    1)可以在项目的入口程序program.cs 的

[STAThread]

static void Main(string[] msg)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Client_Maintenance());
//******msg 就是传过来的参数
Application.Run(new Login());
}
2) 也可以在项目的启动文件,例如 login 等.
在PageLoad 事件中:

string[] args = Environment.GetCommandLineArgs();

if (args.Length > 1)
{
txtLoginName.Text = (args[1].toString()); 注意是: args[1]
}
3.其它 . 还可以得到被调用方Main方法返回的值

private void button1_Click(object sender, EventArgs e)

{
Process da = new Process();
da.StartInfo.FileName = “ConsoleApplicationTest.exe”;
da.StartInfo.UseShellExecute = false;
da.StartInfo.RedirectStandardInput = true;
da.StartInfo.RedirectStandardOutput = true;
da.StartInfo.RedirectStandardError = true;
da.StartInfo.CreateNoWindow = true;
da.Start();
da.WaitForExit();//等待对方退出
int nn = da.ExitCode; //得到返回值
da.Close();
MessageBox.Show(nn.tostring());
}

转载地址:http://kimdi.baihongyu.com/

你可能感兴趣的文章
GDataXMLNode应用小谈
查看>>
做彩票客户端里涉及支付宝相关收获
查看>>
GData 解析Xml以及写xml到文…
查看>>
In App Purchase 详细介绍
查看>>
iOS运行回路(RunLoop)总结
查看>>
《转》iphone线程中使用异步网络的…
查看>>
iPhone开发中静态库中的Category使…
查看>>
去掉字符串中不能作为文件名的特殊…
查看>>
常用SQL说明
查看>>
在iOS中使用重定向,把控制台内容…
查看>>
SQLibs iOS开发常用代码库
查看>>
iOS 开发常用尺寸
查看>>
"/usr/include/sqlite3.h" …
查看>>
ShareKit 中SHK.m中的编译错…
查看>>
Object_c底层细节
查看>>
TortoiseSVN切换登录用户
查看>>
iOS 拨打电话相关知识总结
查看>>
iOS 播放流媒体 服务端配置备份
查看>>
一行代码,在 iPhone 应用中…
查看>>
用UIWebView,JS获取视频链接
查看>>