This short example shows, how to detect the usage of a pipe in a CLI environment to redirect the input buffer of your program to the output of another process.
This code is the minimal API version of a dotnet program. It has been tested on SDK 9.0 on MacOS. By using Console.IsInputRedirected the code detects, if the input buffer has been redirected to the output of the piping process and uses that instead. If the user provides a filename instead, that file is read and printed to the output. If no argument is given, the program waits for the users input and prints that instead.