DOS reverse redirection

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ajetrumpet
Posts: 3
Joined: 01 Nov 2009 00:19

DOS reverse redirection

#1 Post by ajetrumpet » 06 Dec 2009 13:55

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!

sxekjb
Posts: 16
Joined: 07 Nov 2009 19:13

#2 Post by sxekjb » 06 Dec 2009 16:17

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.

SenHu
Posts: 19
Joined: 19 Mar 2009 14:57

#3 Post by SenHu » 07 Dec 2009 11:28

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" }

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: DOS reverse redirection

#4 Post by avery_larry » 07 Dec 2009 12:11

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.

Post Reply