Redirect STDIN Stream for Command to File


How to redirect STDIN stream from the keyboard to an existing file? I want the command to read data from a file.



You can use the "<" redirect operator to redirect the STDIN stream from the keyboard to an existing file as shown below:

command options < file-name

For example, the "SORT" command reads lines from the STDIN stream, sorts them and print them back to the screen.

By default, "SORT" reads lines from the keyboard. But we can redirect it to a file as shown below:

C:\fyicenter>sort < \windows\system32\drivers\etc\hosts

#              # x client host
#          # source server
# Additionally, comments (such as these) may be inserted on individual
# be placed in the first column followed by the corresponding host name.
# Copyright (c) 1993-2009 Microsoft Corp.


Windows Command Syntax

⇒⇒Windows Batch File Tutorials

2017-12-05, 110👍, 0💬