Solved

Sending Inputs to DOS Apps.

Posted on 1998-08-25
5
173 Views
Last Modified: 2010-04-30
Basically, I want to run a DOS executable in a "BATCH" mode.
The original design of the DOS app did NOT take into accout command line arguments, or script files.  SO, what I would like to do is programatically send inputs to a running DOS window (Or any other way possible to run the program repeatedly, and unattended).  Is this possible?
0
Comment
Question by:nbishop
5 Comments
 
LVL 1

Expert Comment

by:raygibbins
ID: 1431003
Try something like this

Dim ret As Long
ret = Shell("Path and Batch Filename", vbNormalFocus)
SendKeys "{RIGHT}", True

0
 

Author Comment

by:nbishop
ID: 1431004
raygibbins.  Your solution seems to work well for Windows applications, but I really need a sendkeys function for a DOS window.
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 170 total points
ID: 1431005
You have to fall back on that old DOS standard, input redirection.

Assuming that your program accepts input from STDIN then you can create a short ASCII text file with the commands in it. Then when you fire the program put:

SHELL( "program < ASCII.TXT", 1)

This will cause the program to accept input from the ASCII file as if it were typed from the keyboard.

FYI you can also capture the program's output by using:

> RESULT.TXT

The sad part of this is that the connections are *NOT* dynamic. Your ASCII.TXT file plays like a macro, no parameter substitution and on interpretation. Thus if your DOS program bumps into an error or some other unexpected condition it'll go south. You also can't read the RESULT.TXT file to find out what is happening until after the DOS program has exited.

0
 

Author Comment

by:nbishop
ID: 1431006
Not exactly what I was hoping to hear, but I think I can work with that.  I have read about an API call to the function sendMessage, but haven't really been successful. Any ideas about that?
0
 

Expert Comment

by:cameron2
ID: 1431007
Make a new project and then add a new commandbutton. Type in this code in your commandbutton. I have tryed this on windows programs and it works But I don’t see why it wont work in dos.  

Sub Command1_Click()
   
MyApp shell("C:\Example.exe", 1) 'You put in your own          
                                 'Program here

AppActivate MyApp                'Runs the program Example.exe  

   'Send the string and hit enter to the current
   'window in "C:\Example.exe"
   SendKeys "This is a simple test{ENTER}"
End Sub
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

13 Experts available now in Live!

Get 1:1 Help Now