Page 1 of 1

DOS reverse redirection

Posted: 06 Dec 2009 13:55
by ajetrumpet
all,

I need some help on how to write a command to the DOS window using the reverse redirection symbol ( < ).

I have searched the internet for hours on trying to get some information on how to do this, but the only i've found is how to redirect OUTPUT to a text file. I need the opposite. I want to redirect the contents of a text file to the command line so I can execute it. Any ideas? Thanks!

Posted: 06 Dec 2009 16:17
by sxekjb
http://ss64.com/nt/for_f.html

You can set different contents of a file as a token and perform a command against it using the for /f command.

Posted: 07 Dec 2009 11:28
by SenHu
Wouldn't the < work in DOS ? Such as

Code: Select all

type < "C:\myfile.txt"


or

Code: Select all

myscript.bat < "C:\myfile.txt"



This is called INPUT REDIRECTION - sending the contents of a file to a command or a script.


You may also consider using biterscripting if that's an option ( http://www.biterscripting.com ) - here is an example of some commands.

Code: Select all

cat < "C:/myfile.txt"


Will catenate or type file C:/myfile.txt

Code: Select all

script myscript.bat < "C:/myfile.txt"

Will execute the script on input from file C:/myfile.txt.

You can also use variables. For example to find out how many lines in file C:/myfile.txt,

Code: Select all

var str content
cat "C:/myfile.txt" > $content
len $content


or you can use inline command directly as

Code: Select all

len { cat "C:/myfile.txt" }

Re: DOS reverse redirection

Posted: 07 Dec 2009 12:11
by avery_larry
ajetrumpet wrote:I want to redirect the contents of a text file to the command line so I can execute it. Any ideas? Thanks!
Depends on what you mean. Can you give examples? I would think the for command is going to do what you want if I understand.