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

x
?
Solved

Sending Inputs to DOS Apps.

Posted on 1998-08-25
5
Medium Priority
?
180 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
[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 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 510 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 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