gpt4 book ai didi

c# - 将文本数据从文件重定向到 stdin c# windows

转载 作者:可可西里 更新时间:2023-11-01 11:08:11 25 4
gpt4 key购买 nike

如何将数据从某个文本文件重定向到 C# 程序的标准输入?通过一些代码或命令提示符(在 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);
}
}
}

但这也不起作用。它崩溃并出现以下错误:

"An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

Additional information: Stream was not writable."

我怎样才能做我想做的事?

最佳答案

Using command redirection operators

 program.exe < input.txt > output.txt 

关于c# - 将文本数据从文件重定向到 stdin c# windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15991361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com