Board index » delphi » Help with old DOS based Turbo Pascal Program

Help with old DOS based Turbo Pascal Program

Someone game me an old DOS based Turbo Pascal program.  It needs to be
fed via keystrokes including arrow keys.  Output goes to a file which
can open and use with all sorts of WIN 95 programs.  I need to run the
program in a loop changing some or all of the inputs each time.  I'd
like to automate this, let in run in the background.  I need a way for
this program to get the keystrokes from a file rather than from the
keyboard. How can this be done?

 

Re:Help with old DOS based Turbo Pascal Program


In article <344bcd9a.56117...@news.earthlink.net>,
        sdan...@earthlink.net (Stephen J. Daniel) wrote:

Quote
>Someone game me an old DOS based Turbo Pascal program.  It needs to be
>fed via keystrokes including arrow keys.  Output goes to a file which
>can open and use with all sorts of WIN 95 programs.  I need to run the
>program in a loop changing some or all of the inputs each time.  I'd
>like to automate this, let in run in the background.  I need a way for
>this program to get the keystrokes from a file rather than from the
>keyboard. How can this be done?

If the program was written to use the DOS input console, then you can use the DOS redirection to feed keystrokes using a file.  The only way you can tell is to try it,

"program.exe < keystrokes.txt"

Re:Help with old DOS based Turbo Pascal Program


Quote
> Someone game me an old DOS based Turbo Pascal program.  It needs to be
> fed via keystrokes including arrow keys.  Output goes to a file which
> can open and use with all sorts of WIN 95 programs.  I need to run the
> program in a loop changing some or all of the inputs each time.  I'd
> like to automate this, let in run in the background.  I need a way for
> this program to get the keystrokes from a file rather than from the
> keyboard. How can this be done?

Write yourself a program that reads a file and sends saved keystrokes to  
keyboard buffer.

Here are routines to write to KeybBuf:

PROCEDURE ClearBuf;
BEGIN
  memW[$0040:$001A] := memW[$0040:$001C];
END;

PROCEDURE WriteBuf(st : STRING);
VAR
 a : INTEGER;
 e : BYTE ABSOLUTE $0040:$001C;

PROCEDURE IncBuf;
BEGIN
  CASE e OF
    $003C : e := $001E;
    ELSE    Inc(e,2);
  END;
END;

BEGIN
  FOR a := 1 TO Length(st) DO BEGIN
    mem[$0040:e] := Ord(st[a]);
    IncBuf;
  END;
END;
--
Dear fellow spammers! Here is some feedback for your bulk mailers:
postmaster@localhost r...@iemmc.org b...@iemmc.org r...@{*word*104}promo.com
r...@agis.net i...@europlace.com

Re:Help with old DOS based Turbo Pascal Program


: Someone game me an old DOS based Turbo Pascal program.  It needs to be
: fed via keystrokes including arrow keys.  Output goes to a file which
: can open and use with all sorts of WIN 95 programs.  I need to run the
: program in a loop changing some or all of the inputs each time.  I'd
: like to automate this, let in run in the background.  I need a way for
: this program to get the keystrokes from a file rather than from the
: keyboard. How can this be done?

1)  Rewrite the program to do what you need it to do
2)  Recompile the existing program to do what you need it to do
3)  Stuff the keyboard buffer and then run the program. If it doesn't
    clear the buffer first, you might be able to run a program first that
    reads the file and stuffs the keyboard buffer. It's kludgey, but
    I admit that this trick worked for one of the programming teams I was
    when we needed a quick fix for some code years ago.

I'm not suggesting #1 just to be a pain. It sounds like the program is not
very complex. The best solution may be a ground-up rewrite to do exactly
what you need instead of warping the old one to do something it won't do well.
--
-------------------------------------------------------------------------
David J. Firth       Study the classics: history, science, philosophy,
Westerville, OH      math, religions, literature & art. Read. Write. Get
                     outdoors. Turn off your PC and go learn something.

Re:Help with old DOS based Turbo Pascal Program


Quote
Stephen J. Daniel wrote:

> Someone game me an old DOS based Turbo Pascal program.  It needs to be
> fed via keystrokes including arrow keys.  Output goes to a file which
> can open and use with all sorts of WIN 95 programs.  I need to run the
> program in a loop changing some or all of the inputs each time.  I'd
> like to automate this, let in run in the background.  I need a way for
> this program to get the keystrokes from a file rather than from the
> keyboard. How can this be done?

This depends.
If the program uses the standard input/output files and doesn't
use Crt, it's quite simple:
DOS (and other OSs) allows to redirect standard input
by using the < character.
So if the program is usually called like this:

  prog param1 param2

instead call it as this

  prog param1 param2 < input.txt

where input.txt is the file containing the keystrokes.
In this case, you don't even have to recompile.

If this doesn't work, you'll have to change the program.
If it was turbo 4.0 or higher, and the program uses Crt,
it may help to simply write

  assign(input,'');
  reset(input);

at the beginning of the main program. This undoes the change
of standard input done by Crt. It won't work, however, if the program
uses other ways to get keystrokes (ReadKey/KeyPressed).
If this is the case, you'll have to rewrite the relevant
parts of the program to use standard input.

Other Threads