Reputation: 11
How I read a file from a command-line in C#? An example command is:
program.exe < textfile
Upvotes: 1
Views: 479
Reputation: 219016
That is sending the file to standard input, so you can get the data stream through the Console.In
property.
Here's a quick proof of concept:
public static void Main(string[] args)
{
var fileContents = System.Console.In.ReadToEnd();
System.Console.Write(fileContents);
}
This was called on the command prompt with:
program.exe < file.txt
Upvotes: 2
Reputation: 11216
As pointed out by P0W, that is a function of cmd.exe, not C#. However, in C#, you would use the various Console.ReadXXX methods to get data from standard input.
Upvotes: 0
Reputation: 47824
Input/Output re-direction works for all executable independent of language.
So just read the file in normal way from standard input
Upvotes: 0