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
evilwinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LucFEMEA Server EngineerCommented:
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
0
evilwinAuthor Commented:
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
0
evilwinAuthor Commented:
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
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

K_2KCommented:
Sure,  often you can.  (Sometimes not, but this one might if it uses standard inputs to get the answers before it goes into game mode.)

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
K_2KCommented:
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/)
0
sirbountyCommented:
You may also try:
  TETRISC 1 11
If K_2k's example works for you - I believe you'll need to place a
  D:
entry just before the
  CD D:\GAMES\TETRIS
line if you're running from C:

What do the 1 and 11 specify in your program?
Is there a TETRIS.INI file in the Tetris folder?  It may allow you to code these properties so you'll never have to respond to them. . .
0
evilwinAuthor Commented:
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
0
sirbountyCommented:
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.
0
evilwinAuthor Commented:
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
0
K_2KCommented:
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"
0
evilwinAuthor Commented:
K_2K,

Your new script worked perfectly.  Thanks.

evilwin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.