Solved

Auto respond with a batch file

Posted on 2003-12-05
11
2,161 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:evilwin
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 32

Expert Comment

by:Luc Franken
ID: 9885492
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
 

Author Comment

by:evilwin
ID: 9886198
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
 

Author Comment

by:evilwin
ID: 9886202
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
 
LVL 8

Accepted Solution

by:
K_2K earned 50 total points
ID: 9888541
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
 
LVL 8

Expert Comment

by:K_2K
ID: 9888582
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 20 total points
ID: 9889404
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
 

Author Comment

by:evilwin
ID: 9894564
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 9901491
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
 

Author Comment

by:evilwin
ID: 9901716
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
 
LVL 8

Expert Comment

by:K_2K
ID: 9902102
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
 

Author Comment

by:evilwin
ID: 9902234
K_2K,

Your new script worked perfectly.  Thanks.

evilwin
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now