provide text file as an input to a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sumant
Posts: 1
Joined: 24 Mar 2015 15:12

provide text file as an input to a batch file

#1 Post by sumant » 24 Mar 2015 15:20

I have a batch file(install.bat which i use to insatll my application) which prompts user with few questions like 'To accept licencse agreement click "y/n". i am thinking to provide the answers from a text file. i have Created a text file with the answers
answers.txt
y
n
y
y

i have Created a another batch file called "wrapper.bat" file that runs install.bat batch and redirects its input from the answers file (wrapper.bat):

@echo off
install.bat < answers.txt

is there any thing that i am missing beacuse its not working properly,i am not sure if install.bat taking some null values from the text file and how install.bat is taking input from answers.txt line by line ?

jwoegerbauer
Posts: 33
Joined: 01 Jan 2013 12:09

Re: provide text file as an input to a batch file

#2 Post by jwoegerbauer » 25 Mar 2015 10:51

I use

Code: Select all

SET /p input=<%text_file%


to read a text file into a DOS batch variable.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: provide text file as an input to a batch file

#3 Post by Squashman » 25 Mar 2015 12:37

Which would work fine if you only needed one question answered.

You can stream in multiple lines by putting multiple set /p commands inside parentheses and redirecting the text file into the code block.

But personally I would create it more like and INI file. Then you could have a single FOR /F command set all the variables.

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: provide text file as an input to a batch file

#4 Post by Compo » 25 Mar 2015 13:14

So, let me get this straight…

You're asking the end user a series of questions, but instead of accepting their response you're forcing your own on them!

…so why bother asking in the first instance?

If you are accepting responses then think about using the CHOICE command's default response with timeout options.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: provide text file as an input to a batch file

#5 Post by foxidrive » 25 Mar 2015 20:46

Compo wrote:You're asking the end user a series of questions


The task looks to be to answer questions asked by the installer program.

I didn't follow it very well to begin with either.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: provide text file as an input to a batch file

#6 Post by foxidrive » 25 Mar 2015 20:48

sumant wrote:i have Created a another batch file called "wrapper.bat" file that runs install.bat batch and redirects its input from the answers file (wrapper.bat):

@echo off
install.bat < answers.txt

is there any thing that i am missing


Yes, the code in your batch files. :D

We don't know what you are doing in them so any answer would be a random guess.

Post Reply