Reputation: 11131
I have a basic C# Console app that looks like this:
static void Main(string[] args)
{
if (args.Length > 0)
{
foreach (var arg in args)
{
Console.WriteLine("arg: " + arg);
}
}
else
{
Console.WriteLine("No args received from standard output.");
}
}
My app will eventually receive data from a third-party app that will pipe data to this console app. In an effort to test this scenario, I tried running the following:
echo "hello world" | MyConsoleApp.exe
When I ran it, I saw No args received from standard output.
. However, I was expecting to see hello world
. What am I doing wrong?
Upvotes: 0
Views: 680
Reputation: 4399
Piped outputs from another command are not passed to your application as command line arguments (i.e. args[]
in Main()
). Rather, they need to be read in by your application from the standard input (stdin
). You need to use Console.Read()
or Console.ReadLine()
for that.
Upvotes: 1