W2k script. command based program needs menu input.

Hi,

I have a program that checks some application things which can be run manually from
a command prompt.
What i want to do is to script it in a batch file ( w2k ) but the program
needs to have input to get to the correct screen inside the program.

Example if run it manually........
c:\> test.exe   ( after i press enter i get to a menu )
The next steps in the program would be choosing menu item " m "
which shows another screen with info that i want want to pipe to a log file. So i would like it
to look something like this

c:\>test > test.log
m
q

It would automatically run the program, enter the menu selection " m ", show info on that screen and then choose " q " for quit.

So how can i enter the inputs that is needed in the script automatically ? The program
is just a ascii menu driven program, dos program. No graphics so the info that comes on the screen should be fine in a log file.

Anyone ?
StorErikMarklundAsked:
Who is Participating?
 
salvagbfConnect With a Mentor Commented:
Ok, a program has to let you send data to it through the command line.  Your's doesn't or the previous solutions might have worked.  This means there has to be something else controlling the operation of this program since the command line can't.

There are 3 parts to this solution...

First, download AutoHotKey (it's free) from download.com at http://download.com.com/3000-2094-10279447.html?tag=lst-0-13

Install it.

There are a bunch of other scripting programs but this one is simple, has a great help file, supports mouse records, will generate scripts for you automatically, and is just what I'm used to.

Now, make a text file, we'll call it program.txt for now.  Rename it with the extension of .ahk.  This makes it an AutoHotKey script file.  Cut and paste the following into the file:

*********************   Don't copy this line  *******************************

WinWait, Program Manager,
IfWinNotActive, Program Manager, , WinActivate, Program Manager,
WinWaitActive, Program Manager,
Run, c:\test\callprog.bat
Sleep, 100
Send, m{ENTER}
Sleep, 50
Send, q{ENTER}
FileCopy, C:\test\output.txt, %A_Mon%-%A_MDay%-%A_Year%.txt
FileDelete, C:\test\output.txt

*********************   Don't copy this line  *******************************


Ok, let's go over that...
The first 3 lines just make sure Program Manager is up and running.  The next line runs a batch file called callprog.bat, I'll get to what that does in a minute.  It then sleeps, sends the letter M, hits enter, sleeps, sends the letter Q, hits enter, copies the output to a txt file with the date as the name, deletes the original output file.

Ok, callprog.bat.  Just make a batch file called that that contains the following:

*********************   Don't copy this line  *******************************

@echo off
call prog.bat > C:\test\output.txt

*********************   Don't copy this line  *******************************


Replace prog.bat with the .exe of the program you're running.  I just used prog.bat for testing purposes.  The rest of the line sends all of the output of what is displayed from the program to output.txt.  output.txt is the file the previous script took and copied to a file with the date as a name.  Make sure you replace/create the directory name too.  To run, just double-click the .ahk file.

This of course will copy all of the output from the program you run.  This probably isn't desireable.  I don't know what kind of output you're dealing with from this program but you can check out the 'filestr' command to try to parse your output.  Something like:

filestr word1 04-29-2004.txt

Or to check for multiple words

filestr "word1 word2 word3" 04-29-2004.txt

I hope that helps!
0
 
YarnoSGCommented:
your arrow needs to be pointing the other direction:

TEST < Test.log
0
 
YarnoSGCommented:
Look up redirection in the Windows Help Index.
0
Get expert help—faster!

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

 
oBdACommented:
If you don't need to hit <return> after typing "m" or "q", try the following command:
echo mq|test.exe
If this doesn't work, create an additional file named, for example, test.txt, with this content:
m
q
Then run the following command:
test.exe <test.txt

If this works, simply add the >YourLogfile at the end of the line.
0
 
StorErikMarklundAuthor Commented:
Hi,

Sorry but that doesnt work. It requieres enter after each menu selection.
It looks like doing as oBdA suggested then program starts and stops
after the first menu is shown, if i then hit enter it goes on in an endless loop until i do cntrl c

So i need the program to start, gets to the first menu, i then need to make a selection and hit enter and it will get me to a new menu that shows info
and then quit.

Anyone ?
0
 
salvagbfCommented:
Hi StorErikMarklund,
What other options does this program have? Does it have options to output anything to a file? Can it accept command line parameters? Also, after you hit m,enter, the text it outputs, does it fit on a single screen, does it scroll, does the ammount of info vary? I've got a solution for running through the selections you need I'm just still working on a way to gather the info output to the screen.
0
 
salvagbfCommented:
There's also a utility in the program folder for AutoHotKey (after you install it of course) that will let you convert the .ahk script into a .exe that'll run on a computer that doesn't have AutoHotKey installed.
0
 
salvagbfCommented:
Also, depending on how fast your program does what it needs to do, you may need to increase the values for 'sleep'.  Try them at increments of 50.
0
 
salvagbfCommented:
The answer I posted with Autohotkey works but probably wasn't as refined for what the asker was exactly looking for, though he never resopnded with more info for resolving the question...
0
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.

All Courses

From novice to tech pro — start learning today.