转自:http://bbs.youkuaiyun.com/topics/190051920#new_post
this.process = new Process();
this.process.StartInfo.CreateNoWindow = true;
this.process.StartInfo.UseShellExecute = false;
this.process.StartInfo.FileName = fileName;
this.process.StartInfo.RedirectStandardError = false;
this.process.StartInfo.RedirectStandardInput = true;
this.process.StartInfo.RedirectStandardOutput = true;
this.process.Start();
StreamWriter sw = this.process.StandardInput;
sw.Write(test);
sw.Close();
string output = this.process.StandardOutput.ReadToEnd();
this.process.WaitForExit();
this.process.Close();
中间的 test、fileName 等变量是我先前定义好的
现在有个问题是:
当我的输出在1000行的时候是完全正常的
但当输出的行为2000或以上时就阻塞了
也就是当输入过多时
string output = this.process.StandardOutput.ReadToEnd();
程序就会在上面一行阻塞
请大家忙帮
给一个解决方案
不胜感激
补充一下
是输出过多时
就是我知道输出会比较多时(一般是1000行以上)
就会阻塞
我也想过可能是输入太多
我把
this.process.StartInfo.RedirectStandardOutput = true;
该成
this.process.StartInfo.RedirectStandardOutput = false;
时
无论输入多少测试数据
程序都正常
是不是StandardOutput有大小限制
如果解决
谢谢
这些我都明白
我说了在数据少的时候运行是正常的
不是完全没有运行
现在还发现一个问题
如果输入超过好几千行
也会出现阻塞
谢谢阿
(再次说下,我已经成功运行了,就是数据输入或输出过多时出现了问题,期待。。。。。。)
缓冲区确实是有大小限制的.而且如果缓冲区满了的话,系统会阻塞等待缓冲区排出适当的数据.
解决办法就是在缓冲区还没有满之前,将缓冲区中的数据输出到某个地方.
另外,一个workaround的方法就是通过重定向符号(>, >>这样的符号,通过调用批处理文件来替代.