Programming Field

CON (console) - DOS/Command Prompt Reference

‘CON’ is a kind of device file name, and refers to the console. Normally, CON will be the screen output if used as an output destination, and be the keyboard input if used as an input source.

CON is almost same as ‘/dev/console’ in Linux. (But due to difference between Windows and Linux, it cannot be said to be exactly the same.)


Usage of CON

If you use ‘CON’ as a file name, you can use the content in the console as an input source or an output target instead of a file. In particular, by specifying ‘CON’ as a file name to the program which reads files, it waits for input on the console, and when finishing input (*), the input data will be used as ‘contents read from a file’. Also, you can make a program, which accepts only the file name as an output destination, to output to the console by specifying ‘CON’.

* ‘Completion of console input’ depends as a general rule on whether ‘only EOF character’ is input. Simply entering a newline will not complete the input, so you must type ‘EOF character’ (Ctrl+Z) and a newline in an empty line to complete.

For GUI applications, which don't usually use console, you cannot use CON for file I/O. And, some console applications cannot use CON as an input or an output. For example, you cannot specify CON to More. (In case of More, you can use CON via input redirection, and if you omit file parameter for More and don't use pipe/redirections, More uses the console.)

* Similarly for other device files, using CON concatenated with existing directory path (such as C:\Windows\CON) will result to use the console. And, ‘CON’ is a reserved name by system and you cannot use CON as a file/directory name.
* Using ‘CON’ always treat console as input source/output target. As a result, you cannot pass outputs with output redirection or pipe operator while using ‘CON’ as an output target. (You cannot even capture CON output with ‘for /F’.)


Sample 1

type CON > save.txt

Type command requires a file name for input source, and outputs its content. Therefore requesting key input by specifying ‘CON’ and redirecting output to ‘save.txt’ allow to create a file with the content from key input.

Sample 2

echo test > CON

Prints ‘test’ to the screen. (For typical prompt the output is the console (CON) so you don't have to specify CON such above.)