Check if Input, Output and Error is redirected on the Console or not in C#

CsharpServer Side ProgrammingProgramming

To check if the input is redirected on the Console or not, the code is as follows −

Example

 Live Demo

using System;
public class Demo{
   public static void Main(string[] args){
      Console.WriteLine("Input Redirected? = "+Console.IsInputRedirected);
   }
}

Output

This will produce the following output −

Input Redirected? = False

Example

To check if the output is redirected on the Console or not, the code is as follows −

 Live Demo

using System;
public class Demo{
   public static void Main(string[] args){
      Console.WriteLine("Output Redirected? = "+Console.IsInputRedirected);
   }
}

Output

This will produce the following output −

Output Redirected? = False

Example

To check if the error is redirected on the Console or not, the code is as follows −

 Live Demo

using System;
public class Demo{
   public static void Main(string[] args){
      Console.WriteLine("Error Redirected on Console? = "+Console.IsErrorRedirected);
   }
}

Output

This will produce the following output −

Error Redirected on Console? = True
raja
Published on 11-Dec-2019 05:44:14
Advertisements