这个控制台程序是用其它语言写的,我想在C#中调用它,并传入一些内容,然后得到该控制台输出的数据,请问怎么做,谢谢
解决方案 »
- socket文件传输 运行问题
- socket!!
- 一卡通,不同系统融合问题
- 求救:DataGridView在编辑状态按回车有没有办法跳到右边一格?
- Oracle存储过程是不是只能用OracleParameter填参数?我用exec procedurename(parameter)执行怎么都不成功
- 我是这样动态取数据的,请问怎么样才能在DELETE 按钮上写代码删除DATAGRID的当前记录?
- 从managed module 到assembly 。
- 麻烦看下下面代码,在后台处理本地文件并上传到服务器的指定目录
- 在form窗体里面做百度地图
- 如何获取当前应用程序所在目录信息
- 什么叫b/s c/s接入系统平台测试
- 用JavaScript访问服务器控件
Process p = new Process();
p.StartInfo.FileName = exePath; //设定程序名
p.StartInfo.Arguments = command; //设定程序执行参数
p.StartInfo.UseShellExecute = false; //关闭Shell的使用
p.StartInfo.RedirectStandardInput = true; //复位向标准输入
p.StartInfo.RedirectStandardOutput = true; //复位向标准输出
p.StartInfo.RedirectStandardError = true; //复位向错误输出
p.StartInfo.CreateNoWindow = false; //设置不显示窗口 p.Start(); //启动 //p.StandardInput.WriteLine(command); //输入要执行的命令
//p.StandardInput.WriteLine("exit"); //Exit return p.StandardOutput.ReadToEnd();
其中 INPUT 为输入,OUTPUT 为输出。
Process p = new Process();
p.StartInfo.FileName = exePath; //设定程序名
p.StartInfo.Arguments = command; //设定程序执行参数
p.StartInfo.UseShellExecute = false; //关闭Shell的使用
p.StartInfo.RedirectStandardInput = true; //复位向标准输入
p.StartInfo.RedirectStandardOutput = true; //复位向标准输出
p.StartInfo.RedirectStandardError = true; //复位向错误输出
p.StartInfo.CreateNoWindow = false; //设置不显示窗口 p.Start(); //启动 p.StandardInput.WriteLine(command); //输入要执行的命令
String output = p.StandardOutput.ReadToEnd();
p.StandardInput.WriteLine("exit"); //Exit return output;
这样比较好看= =
输入之后就会输出一个字符串True或False,我如何拿到这个输出的字符串呢?
p.StandardInput.WriteLine(姓名+“\r\n”);
output=控制台中所有内容
可考虑
if(output.IdexOf("True")>-1)
true
else
false
或者截取IndexOf(姓名),Length-LastIndexOf("\r\n")
情况一:
请输入学号:123456
请输入姓名:yy
true情况二:
请输入学号:123456
请输入姓名:gg
false
using System;
using System.Collections.Generic;
using System.Text;namespace t1
{
class Program
{
static void Main(string[] args)
{
Console.Write("请输入学号:");
String a=Console.ReadLine();
Console.Write("请输入姓名:");
String b=Console.ReadLine();
if (a.Length > 5)
Console.Write("true");
else
Console.Write("false");
}
}
}
调用
Process p = new Process();
p.StartInfo.FileName = "d:\\t1.exe"; //设定程序名
p.StartInfo.Arguments = null; //设定程序执行参数
p.StartInfo.UseShellExecute = false; //关闭Shell的使用
p.StartInfo.RedirectStandardInput = true; //复位向标准输入
p.StartInfo.RedirectStandardOutput = true; //复位向标准输出
p.StartInfo.RedirectStandardError = true; //复位向错误输出
p.StartInfo.CreateNoWindow = false; //设置不显示窗口 p.Start(); //启动 p.StandardInput.WriteLine(this.textBox1.Text); //输入要执行的命令
p.StandardInput.WriteLine("000000"); String output = p.StandardOutput.ReadToEnd();
p.StandardInput.WriteLine("exit"); //Exit this.label1.Text= output;this.textBox1.Text="1111111111";返回 请输入学号:请输入姓名:true
this.textBox1.Text="11";返回 请输入学号:请输入姓名:false
但是如果你控制台程序不是这样的出口- -……
<<变成true就能隐藏2、直接读貌似也可以……,就是麻烦点3、应该是能拿到的,和你直接用命令行一样
string line = reader.ReadLine();//每次读取一行
重新定向下