Sea*_*ess 1 c# windows redirect stdin file
如何将数据从某些文本文件重定向到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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这也不起作用。它因以下错误而崩溃:
“ mscorlib.dll中发生了'System.ArgumentException'类型的未处理异常
附加信息:流不可写。”
我该怎么办?
归档时间: |
|
查看次数: |
3931 次 |
最近记录: |