Tricksy
Tricksy

Reputation: 35

How to use command: command < text file in cmd batch?

Please help me how to use command as "command < file.txt" I don't know this command is used like. Give me a few examples. Thanks!

Upvotes: 1

Views: 97

Answers (2)

Sam Denty
Sam Denty

Reputation: 4085

command.exe < file.txt

That command would redirect the contents of file.txt to command.exe.


For example, if file.txt contained hello world,  then set /p var=<file.txt would result with the contents of file.txt to be stored to %var%.

A complete batch file script utilising command redirection would be:

@echo off
echo hello 1234 > doc.txt
set /p contents = < doc.txt
echo The contents of "doc.txt"="%contents%"
pause
exit

Here are some links that further explain command redirection:
http://robvanderwoude.com/battech_redirection.php
http://ss64.com/nt/syntax-redirection.html

Upvotes: 3

Akhil Job
Akhil Job

Reputation: 419

http://www.robvanderwoude.com/battech_redirection.php Visit the above link to know more about redirecting output from CMD to text files

Upvotes: 1

Related Questions