Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect when output is being redirected?

I have a Win32 application written in C that can have its console output via printf() redirected to a log file.

It would be nice if I could have my app. detect if it had been started with or without a redirect '>'.

Any ideas?

like image 202
logout Avatar asked Jan 18 '10 17:01

logout


People also ask

Which symbol is used for redirecting the output?

The > symbol is known as the output redirection operator. The output of a process can be redirected to a file by typing the command followed by the output redirection operator and file name.

What is output redirection?

Output redirection is used to put output of one command into a file or into another command.

What operator redirect output to another program?

This is known as redirecting output. Redirection is done using either the ">" (greater-than symbol), or using the "|" (pipe) operator which sends the standard output of one command to another command as standard input.

What is input output redirection?

Input/Output (I/O) redirection in Linux refers to the ability of the Linux operating system that allows us to change the standard input ( stdin ) and standard output ( stdout ) when executing a command on the terminal. By default, the standard input device is your keyboard and the standard output device is your screen.


1 Answers

Method from Microsoft: WriteConsole fails if it is used with a standard handle that is redirected to a file. If an application processes multilingual output that can be redirected, determine whether the output handle is a console handle (one method is to call the GetConsoleMode function and check whether it succeeds).

like image 96
crea7or Avatar answered Oct 12 '22 13:10

crea7or