C#学习(4)——使用shell调用外部exe应用
2015-04-06 18:14
337 查看
一 首先创建一个windows窗体程序,在其中增加一个Button,以及一个TextBox
二 接下来我们首先在命令提示行中调用我们之前就写过的HelloWorld
C:\Users\gao\Desktop\Hello.exe 代表我的Hello生成应用的位置,随后跟着的两个字符串代表Hello要使用的两个参数,之后enter既得到结果
三 接下来就要使用Button将Hello.exe运行结果输出到TextBox里
双击Button,添加代码
运行结果如下:
Author——峰烨
二 接下来我们首先在命令提示行中调用我们之前就写过的HelloWorld
C:\Users\gao\Desktop\Hello.exe 代表我的Hello生成应用的位置,随后跟着的两个字符串代表Hello要使用的两个参数,之后enter既得到结果
三 接下来就要使用Button将Hello.exe运行结果输出到TextBox里
双击Button,添加代码
private void button1_Click(object sender, EventArgs e) { Process process = new Process(); process.StartInfo.FileName = "cmd.exe"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.Start(); string str = @"C:\Users\gao\Desktop\Hello.exe"+" fengye C#"; process.StandardInput.WriteLine(str); process.StandardInput.WriteLine("exit"); string sh = process.StandardOutput.ReadToEnd(); process.Close(); this.textBox1.Text = sh; }
运行结果如下:
Author——峰烨
相关文章推荐
- [Android]Recovery调用外部Shell脚本,Shell脚本使用ui_print方法
- Unity调用外部Shell脚本或exe
- c++ 调用外部程序exe-ShellExecuteEx
- Unity调用外部EXE或Shell命令
- Unity调用外部EXE或Shell命令
- windows下调用外部exe程序 SHELLEXECUTEINFO
- C#使用Process类调用外部exe程序
- C#使用Process类调用外部exe程序
- 使用Qprocess的startDetached()方法调用外部exe程序
- 让Delphi使用带参数来调用外部可执行文件(EXE文件)
- 【VBScript Shell】使用vbs shell调用命令行exe的示例代码
- windows下调用外部exe程序 SHELLEXECUTEINFO
- 使用C#调用外部Ping命令获取网络连接情况(转——主要是对dos命令应用)
- fscommand调用外部EXE文件
- 使用C#调用外部Ping命令获取网络连接情况
- 使用C#调用外部Ping命令获取网络连接情况
- 调用cmd.exe程序和外部程序(转)
- 使用C#调用外部Ping命令获取网络连接情况!
- C#调用外部可执行exe文件
- 使用C#调用外部Ping命令获取网络连接情况