Link to home
Start Free TrialLog in
Avatar of evilwin
evilwin

asked on

Auto respond with a batch file

I would like to set up a batch file to run a game.  The first two prompts from the game are to select the graphics mode and the sound option.  My answers are always "1" and "11", respectively.  How do I get the .bat file to make those responses for me so the game starts immediately?  Right now, the .bat file is tetris.bat and looks like this

cd d:\games\tetris
tetrisc

Thanks.

And if you happen to know a good online source for how to write .bat files, I'd appreciate it.

evilwin
Avatar of Luc Franken
Luc Franken
Flag of Netherlands image

Hi evilwin,

If your game doesn't support it, it can't be done trough a batch file. Try from a dos prompt:
cd d:\games\tetris
tetrisc /?
see if it comes up with something, if it doesn't, you're out of luck on this one :-(

For learning how to write batch files, this should be a right way to start =>  http://www.chebucto.ns.ca/~ak621/DOS/BatBasic.html

Greetings,

LucF
Avatar of evilwin
evilwin

ASKER

Hi LucF,

What do you mean by "comes up with something"?  I ran the commands "tetrisc /?" and "tetrisc /1".  In both instances, the game ran like it always does - I had to type in "1" and "11" myself.  What should "/?" do?

This is an old game (early 1992), so I have reason to hope it works well with batch files.  I remember reading sometime ago about creating plain text files that included appropriate inputs.  For example, the file yes.txt (or yes.bat ?) might simply be:

y

Then these files can be called to respond to program prompts.  Also, I've been told that you can specify inputs directly on the command line, but I don't know how.  Is this what you were suggesting?

Well, if this can't be done, then it can't be done.  I'll leave the question open a little longer to see if anybody else has ideas.  Thanks for the batch tutorial link.

evilwin
Avatar of evilwin

ASKER

Hi LucF,

What do you mean by "comes up with something"?  I ran the commands "tetrisc /?" and "tetrisc /1".  In both instances, the game ran like it always does - I had to type in "1" and "11" myself.  What should "/?" do?

This is an old game (early 1992), so I have reason to hope it works well with batch files.  I remember reading sometime ago about creating plain text files that included appropriate inputs.  For example, the file yes.txt (or yes.bat ?) might simply be:

y

Then these files can be called to respond to program prompts.  Also, I've been told that you can specify inputs directly on the command line, but I don't know how.  Is this what you were suggesting?

Well, if this can't be done, then it can't be done.  I'll leave the question open a little longer to see if anybody else has ideas.  Thanks for the batch tutorial link.

evilwin
ASKER CERTIFIED SOLUTION
Avatar of K_2K
K_2K

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
here's a couple starters for reference, more than tutorials.
MS themselves have some help also.

http://www.easydos.com/dosindex.html 
http://users.cybercity.dk/~bse26236/batutil/help/INDEX.HTM

Good Luck,
2K
(\o/)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of evilwin

ASKER

K_2K:  Your method worked!  Well, not exactly, but close enough.  The commands "echo 1 >" and "echo 11 >" output "1 " and "11 ", not "1" and "11".  That is, they include a trailing space.  Removing the space between the "1"/"11" and the ">" in the command line fixes the problem for 11, but not for 1.  For some reason, the command "echo 1>" causes the statement "ECHO is on." to be printed to answer.txt, instead of just a "1".  I got around this by making a permanent answer.txt file instead of having the .bat file generate it.  But this is what I was looking for, so thanks.

sirbounty:  1 and 11 specify the graphics mode and the sound setup, respectively.  There are configuration files in the Tetris folder, but they aren't text files.  And your advice for including the "D:" line was useful, as I ultimately saved the .bat file to my desktop.  Thanks.

I'll leave the question open one more day for comments.

evilwin
BTW evilwin, the /? switch usually lists the applicable parameters that a file can use.
For instance, if you type:
DIR /?
from the command prompt, it will list options you can use.

A couple of options to try for this application, if /? doesn't help you are:

TETRISC < 1 11
TETRISC < "1 11"
TETRISC < "1" "11"
TETRISC 1 11
TETRISC "1 11"
TETRISC "1" "11"
TETRISC | 1 11
(the pipe symbol "|" above is created by holding shift and the backspace key - may not work, but worth a try).

If these don't work, you're on the right track creating the answer.txt yourself, as the script above would recreate it every time you ran the program (not a BIG deal, but not necessarily the most efficient use of coding - no offense K_2K)

Otherwise, if any of the above lines work for you, a batch file probably isn't even necessary, if you're running some version of windows.
Right-click the desktop, New->Shortcut and enter the command line of whichever of the above works for you (including the full path) and then name the shortcut anything you like.  Again, not a huge space saver (shortcut vs. batch file) - just better practice.
Avatar of evilwin

ASKER

sirbounty:  I tried the suggestions in your most recent post, but none of them worked.  Worth a try, though.  As for coding style, the one thing I did like about K_2K's approach is that the .bat file generated the answers to the prompts on the fly, so it was not dependent on the pre-existence or integrity of another file.  Also, answer.txt was created in the system temp folder so it was out of sight, out of mind, and would be discarded with every periodic cleaning I do.  But the setup I have now works fine, so let the nostalgia begin.  :-)

Thanks for the help everyone.

I'll increase the points to 70.
K_2K: 50
sirbounty: 20
Grade: A
Sorry, been busy.
space at end of line is easy to fix by placing the redirect before the command.  The space between that and the echo command will have no effect,  and there will be no space after the "1" and "11" to cause problems in the file.  Having a permanently correct file as you have set up is fine, of course, but for future reference if you want to create them "on the fly", here's what I should have given you the first time

Enjoy,
2K
(\o/)

::starttet.bat
::write file
>"%temp%\answer.txt" echo 1
>>"%temp%\answer.txt" echo 11

::start game using file as input
cd d:\games\tetris
tetrisc <"%temp%\answer.txt"
Avatar of evilwin

ASKER

K_2K,

Your new script worked perfectly.  Thanks.

evilwin