Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Auto respond with a batch file

Posted on 2003-12-05
11
Medium Priority
?
2,238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 32

Expert Comment

by:LucF
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 8

Accepted Solution

by:
K_2K earned 200 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
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 80 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

715 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