如何将数据从某些文本文件重定向到C#程序的stdin?通过某些代码或命令提示符(在Windows中)?我试着在命令提示符下重定向它,如下所示:input.txt>program.exe>程序;output.txt(像在linux中一样),但这不起作用。也这样尝试过:
string path = @"D:\input.txt";
// Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
using (StreamWriter stdinput = new StreamWriter(Console.OpenStandardInput()))
{
while ((s = sr.ReadLine()) != null)
{
stdinput.WriteLine(s);
}
}
}
但这也没有奏效。它因以下错误而破碎:
“中发生了类型为“System.ArgumentException”的未经处理的异常
mscorlib.dll
附加信息:流不可写。"
我该怎么做我想做的事?