1
如何将数据从某些文本文件重定向到C#程序的stdin?通过一些代码或命令提示符(在Windows中)?我已经尝试在命令提示符中重定向它,如下所示:input.txt> program.exe> output.txt(如在Linux中),但这不起作用。也试过这样:将文本数据从文件重定向到stdin c#windows
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);
}
}
}
但是这也没有工作。它挤压以下错误:
"An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Additional information: Stream was not writable."
我该怎么做我想要的?
谢谢,这帮助! – Seatless