VOGONS


First post, by etadeu

User metadata
Rank Newbie
Rank
Newbie

Is there a way to automate an old DOS application (running inside DOSBox) programatically from outside (e.g., with a program written in C or from Python)? I would like to send keys and strings to the application, detect updates to the DOS "screen" and get the application output.

It would be even better if the DOS application could run "hidden", i.e., not showing in the taskbar.

Note: It is not a game, it is one of those old application where you are given menus with press 1 for something, press 2 for something else, etc... then it asks for some input numbers, and then it shows some results. It is a pure console application.

If there isn't any easy way, what is the best "path" to develop this? Changing the DOSBox code to add hooks? Where would I need to change?

Thanks in advance!

Reply 1 of 5, by frobme

User metadata
Rank Member
Rank
Member

You would pretty much have to modify the source code if you wanted it to work universally (on every platform DOSBox supports). However for each OS that DOSBox runs in, there are methods to send data to DOSBox and make it LOOK like it came from the OS as input, so that is one method to do it right now without modifying code. You would not however be aware from "outside" of anything about DOSBox state, so timing issues and such might make it quite difficult.

For instance, under Windows the concept is quite simple - find the DOSBox window handle (a variety of Windows API calls let you determine this, either from EXE name, title name, etc), then dispatch a message to that window directly which is the keyboard message. There's even an API call for this (SendKeys).

Similar systems exist on the other OSes.

-Frob

Reply 2 of 5, by etadeu

User metadata
Rank Newbie
Rank
Newbie

Thanks! Is there a way to retrieve information from the DOSBox screen on windows too?

Reply 3 of 5, by frobme

User metadata
Rank Member
Rank
Member

Is there a way to retrieve information from the DOSBox screen on windows too?

There is, but it is quite laborious. You can convert the DOSBox window into a DIB and retrieve it from another app...but at that point it would be much simpler and straightforward to modify DOSBox in source to support your particular use.

Essentially, it's very easy to get things IN by pretending you are a keyboard or a mouse. Getting state OUT is difficult, even when you know exactly what you are looking for (like reading "Press 1 to continue" on the screen). If you modified DOSBox itself and you were in a text mode, you could just read the framebuffer and find that string very easily. Figuring it out from a fetched Windows DIB could be quite a pain.

-Frob

Reply 4 of 5, by Pickle

User metadata
Rank Member
Rank
Member

Use SDL to send intputs. You can use SDL_Pushevent for example.

This idea about looking at the frame buffer for feedback seems like too much work (and kind of odd way of doing it)
If your going to use the source would it not be better to hook into dosbox's internal command queue? Find where dosbox handles commands/command line input and have it send a copy to the host code.

Reply 5 of 5, by Kippesoep

User metadata
Rank Oldbie
Rank
Oldbie
Pickle wrote:

If your going to use the source would it not be better to hook into dosbox's internal command queue? Find where dosbox handles commands/command line input and have it send a copy to the host code.

That will usually not work. Very few programs use the BIOS routines for text display. Many libraries write to the frame buffer directly. It also would be nasty when the cursor position is changed. Reading from the frame buffer is the only reliable way of determining what is displayed.