我现在再弄一个编程程序,当我把以下代码,转换成exe 去调用时候
using System;
using System.Collections.Generic;
using System.Text;
namespace Demo1aaa
{
class Program
{
private void Func(int[] Arg)
{
for (int i = 1; i < Arg.Length; i++)
{
int a = 0;
for (int j = 0; j < Arg.Length-i; j++)
{
if (Arg[j] > Arg[j + 1])
{
a = Arg[j + 1];
Arg[j + 1] = Arg[j];
Arg[j] = a;
}
}
for (int k = 0; k < Arg.Length; k++)
{
Console.WriteLine(Arg[k]);
}
Console.ReadLine();
}
}
static void Main(string[] args)
{
Program p = new Program();
int[] Arg = { 130, 28, 345, 299, 40, 30, 201 };
p.Func(Arg);
}
}
}
我使用下面代码去调用的时候exe 的时候
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = path;
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
p.StartInfo.CreateNoWindow = true;//不显示程序窗口
p.Start();//启动程序
p.StandardInput.WriteLine("exit");
//p.StandardOutput.EndOfStream
string txtresult = p.StandardOutput.ReadToEnd();
因为存在 Console.ReadLine(); 这个代码,所以得到返回值的时候会一直死掉
加了这个 p.StandardInput.WriteLine("exit");也没用。有哪位大神,遇到过这总情况,麻烦指点一下