Solved

Sending Inputs to DOS Apps.

Posted on 1998-08-25
5
176 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

791 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