Solved

W2k script. command based program needs menu input.

Posted on 2004-04-28
12
165 Views
Last Modified: 2010-04-13
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 ?
0
Comment
Question by:StorErikMarklund
12 Comments
 
LVL 7

Expert Comment

by:YarnoSG
ID: 10942420
your arrow needs to be pointing the other direction:

TEST < Test.log
0
 
LVL 7

Expert Comment

by:YarnoSG
ID: 10942429
Look up redirection in the Windows Help Index.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 10942499
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:StorErikMarklund
ID: 10946732
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
 
LVL 6

Expert Comment

by:salvagbf
ID: 10951177
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
 
LVL 6

Accepted Solution

by:
salvagbf earned 500 total points
ID: 10951852
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
 
LVL 6

Expert Comment

by:salvagbf
ID: 10951924
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
 
LVL 6

Expert Comment

by:salvagbf
ID: 10952024
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
 
LVL 6

Expert Comment

by:salvagbf
ID: 12319351
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

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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