"StandardIn尚未重定向";.NET(C#)中的错误 [英] "StandardIn has not been redirected" error in .NET (C#)
本文介绍了"StandardIn尚未重定向";.NET(C#)中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用stdin做一个简单的应用程序.我想在一个程序中创建一个列表,然后在另一个程序中打印它.我想出了以下内容.
I want to do a simple app using stdin. I want to create a list in one program and print it in another. I came up with the below.
我不知道app2是否可以工作,但是在app1中却收到异常"StandardIn尚未重定向".在writeline上(在foreach语句内).我该怎么做?
I have no idea if app2 works however in app1 I get the exception "StandardIn has not been redirected." on writeline (inside the foreach statement). How do I do what I intend?
注意:我尝试将UseShellExecute设置为true和false.两者都会导致此异常.
NOTE: I tried setting UseShellExecute to both true and false. Both cause this exception.
//app1
{
var p = new Process();
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = @"path\bin\Debug\print_out_test.exe";
foreach(var v in lsStatic){
p.StandardInput.WriteLine(v);
}
p.StandardInput.Close();
}
//app 2
static void Main(string[] args)
{
var r = new StreamReader(Console.OpenStandardInput());
var sz = r.ReadToEnd();
Console.WriteLine(sz);
}
推荐答案
您永远不会启动()新进程.
You never Start() the new process.
这篇关于"StandardIn尚未重定向";.NET(C#)中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文