Solved

Scripting a Foxbase program running under windows command prompt

Posted on 2009-04-06
20
2,548 Views
Last Modified: 2012-06-21
I have been tasked with automating a Foxbase program that has been in use in my company for some time. The program is used to combine output files from a capture taken from another script that runs on an emulated VAX host. The foxbase script I am looking to automate runs in an MS-DOS prompt under windows.

I have experimented with triggering and controlling this program with VB-Script. However, the best I can do is to trigger the program to execute in a separate DOS shell. I cannot use VB-Script to enter commands into the program's prompts. I am wondering if there is a way to do this easily with a scripting language or automation tool?

I have experimented with various automation tools such as HP QuickTestPro to no avail. QTP does not seem to recognise the foxbase application as another element that you can automatically control. It sees instead, another command prompt. That's it. It does not seem to recognise the commands being typed into the program.

When I use VB-Script to program cmd prompts, the text typed does not appear anywhere in either the foxbase program or the original cmd prompt until the Foxbase program has ended and the focus is back onto the original cmd prompt that spawned the process.

I realise that the only solution may well in fact be to re-write the foxbase application in another more user-friendly language. However, I'm not in possession of the source code and am not sure exactly what this program does in its entirety. I'm essentially looking for the simplest and quickest solution.

Any ideas would be very much appreciated.
0
Comment
Question by:james_j_hedges
  • 9
  • 5
  • 3
  • +3
20 Comments
 
LVL 17

Expert Comment

by:Jared Luker
ID: 24081338
Is it just a command line utility that you need to pass parameters to?

You can just use the input box method to get the parameters and the .run method to do the actual executing.
0
 
LVL 41

Assisted Solution

by:pcelba
pcelba earned 100 total points
ID: 24081477
What is the size of Foxbase program you have to trigger? What are the file extensions (this could help to recognize Fox version)? How many characters you have to enter? Do you have the app folder listing?

It should be possible to rewrite the fox application or to call it from another fox application which could simulate the keyboard input but it is almost impossible without source code knowledge. The source is possible to recover from the application but then it will need some experienced person to decide what to do.
0
 
LVL 12

Assisted Solution

by:jrbbldr
jrbbldr earned 100 total points
ID: 24083059
"re-write the foxbase application in another more user-friendly language"  - assuming that you indeed had to do a re-write, that would not be the most expedient approach.

If you have ever done a code conversion of an application, you know that changing the entire language is an EXTENSIVE undertaking.  Each and every aspect of the original code has to be 100% understood so that it can be re-written into a different language using that new language's syntax and native methodology.   Depending on the complexity of the application and your knowledge of the original code and its language, this can turn out to be a LARGE task.

"not in possession of the source code and am not sure exactly what this program does in its entirety" - those 2 statements might make it impossible for you to re-write the code into another language.

Instead, if you had to re-write it, you should convert it into a Visual Foxpro 9 application which could utilize most all of the existing code 'as is'.   You should be able to use a tool like ReFox to decompile the original code into source and then migrate it into VFP9 - some things would most likely need changing, but it is a do-able project.

That would enable you to add the features you want and end up with an application that supports 21st century program requirements.

Alternatively, have you considered the possibility of wrapping the old application into Web Services and/or using an SOA approach to 'drive' it?   Do a Google search for -  "web services" wrap old application

Good Luck

0
 
LVL 8

Expert Comment

by:mikegagnon
ID: 24083573
pcelba

>>>this could help to recognize Fox version

Foxbase is pre-foxpro, not actually Foxpro.
http://www.foxprohistory.org/foxprotimeline.htm
0
 

Author Comment

by:james_j_hedges
ID: 24084660
The fox program is a command line program but it seems to run in a seperate command prompt. It looks as if windows is running it in an emulated 16-bit virtualised environment. I think that may be causing the issues with identifiying what is being typed into the command window

I'm not really sure what is meant by the reply by jared_luker:

"You can just use the input box method to get the parameters and the .run method to do the actual executing." Are you referring to VBScript or the foxbase code?
foxbase-screenshot.JPG
0
 
LVL 41

Expert Comment

by:pcelba
ID: 24084723
Mike,
thanks for the link. Could you please tell, how do I recognize which fox version is used for above application? We are even not sure if it is FoxBase or FoxPro or something else. It was the reason for my questions.
0
 

Author Comment

by:james_j_hedges
ID: 24084732
Upon further investigation and doing some more asking around, it appears that this program is in fact a compiled pascal application and not fox.
Program SPMake;

var

  f : text;

  w : text;

  In_file : String[12];

  In_pref : String[8];

  out_file : String[12];

  lines   : longint;

  suffix  : String[3];

  Alldone : Boolean;

  file_no : integer;

  c : char;

  asc : longint;
 

begin

  Write('Name of SPOOL files -> ');

  Readln(In_file);

  if (length(In_file)=0) or (pos('.',In_file)>0) then

  begin

    writeln('Invalid SPOOL file name.');

    halt;

  end;
 

  Write('File to be created -> ');

  Readln(Out_file);
 

  if (length(Out_file)=0) or (pos('.',Out_file)>9)

  or ((pos('.',In_file)=0) and (length(In_file)>8)) 

  or (length(Out_file)>12)   then

  begin

    writeln('Invalid output file name.');

    halt;

  end;

  In_Pref:=In_file;
 

  Assign(w, out_file);

  Rewrite(w);

    
 
 

  Alldone := False;
 

  file_no:=0;

  while not alldone do 

  Begin

    file_no:=file_no+1;

    str(file_no,suffix);

    while length(suffix)<3 do suffix:='0'+suffix;
 

    In_file:=In_pref+'.'+suffix;  

    Assign(f, In_file);

    {$I-}

    Reset(f);

    {$I+}

    If IOResult<>0 then

    begin

      Alldone:=True;

      if suffix='001' then 

      begin

        write('File ',in_file,' not found.');

        halt;

      end;

    end else

    begin  

      lines:=0;

      writeln('Reading ', In_file, ' into ',out_file);

      while not eof(f)  do

      begin

        read(f,c);

        asc:=ord(c);

        if (asc>9) and (asc<>29) then write(w,c);
 

        {if (asc>= 13) and (asc <= 126) then write(w,c);}

      end;

      close(f);

      erase(f);

    end;

  end;    

  Close(w);

  Writeln('Files combined.');

end.

Open in new window

0
 
LVL 41

Expert Comment

by:pcelba
ID: 24084830
So you have everything. The program combines several input files into one output file with some characters filtering.  It should be easy to port this program into any other language. If you need it in FoxPro language just let us know in FoxPro Database zone.

Good luck!
0
 

Author Comment

by:james_j_hedges
ID: 24084871
The program doesn't need to be in fox. The only reason I assuemd it was fox was that a lot of our other programs are coded in that language.

I know that other developers here have already tried to re-code this application into another language but found that the output file was slightly different. This meant that the programs that read this file had issues. Can anyone suggest a solution for either automating this pascal program or re-writing it in another language such that the output is identical?

Thanks for your help!
0
 
LVL 8

Assisted Solution

by:mikegagnon
mikegagnon earned 100 total points
ID: 24085780
pcelba

>>>>I have been tasked with automating a Foxbase program that has been in use in my company for some time.

I thought the first line of the original question was clear. Do you read something different?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 41

Expert Comment

by:pcelba
ID: 24086653
Mike, as you may see my doubts were more than rightful :-). How many people here know difference between Foxbase and FoxPro? BTW, do you know what was Dbase II+?

But I am afraid our discussion cannot help here. Better solution would be some example of the requested automation. Unfortunately, we still don't know what is the preferred language. Can it be done in Visual FoxPro?
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 200 total points
ID: 24087020
from my pascal knowledge I see that there are two Readln() lines, that ask a user for interactive input. You might be able to "automate" that by putting the two filenames on the keyboard buffer, each with a CRLF after the name, before running that program, and then it'll not ask for the file names. But in itself this is not meant for automating. Perhaps piping some file with the needed input to stdin, something like that. You better ask in a Pascal section (if there is one here) with that source code.

Bye, Olaf.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 24087532
It is possible to update any program to accept command line parameters. Then it is not necessary to play with keyboard buffer and the task may be automated, scheduled, included into a batch etc.

The only thing to define is error handling and reporting because it probably cannot interact directly to users. So, each run should create some log file about its results.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 24088081
The question was asked in FoxPro zone, so here is the Pascal code switched into VFP language. If it will be compiled into EXE then you have to provide two parameters - Input and Output files. Suppose these files are in program default folder. The error handling should probably be updated to create the log file. Variable names are unchanged to better see the language differences.


*Program SPMake;

*var

*  f : text;

*  w : text;

*  In_file : String[12];

*  In_pref : String[8];

*  out_file : String[12];

*  lines   : longint;

*  suffix  : String[3];

*  Alldone : Boolean;

*  file_no : integer;

*  c : char;

*  asc : longint;
 

LPARAMETERS In_file, Out_file
 

LOCAL In_pref, Alldone, file_no, w, f, suffix
 

ON ERROR DO l_err WITH ERROR(), MESSAGE(), LINENO()
 

*begin

*  Write('Name of SPOOL files -> ');

*  Readln(In_file);

*  if (length(In_file)=0) or (pos('.',In_file)>0) then

*  begin

*    writeln('Invalid SPOOL file name.');

*    halt;

*  end;
 

IF EMPTY(In_file) OR '.' $ In_file OR LEN(In_file) > 8

  DO l_err WITH 0, "Invalid SPOOL file name."

ENDIF
 

*  Write('File to be created -> ');

*  Readln(Out_file);

 

*  if (length(Out_file)=0) or (pos('.',Out_file)>9)

*  or ((pos('.',In_file)=0) and (length(In_file)>8))   && this test was moved to In_file

*  or (length(Out_file)>12)   then

*  begin

*    writeln('Invalid output file name.');

*    halt;

*  end;
 

IF EMPTY(Out_file) OR AT('.', Out_file) > 9 OR LEN(Out_file) > 12

  DO l_err WITH 0, "Invalid output file name."

ENDIF
 

*  In_Pref:=In_file;
 

In_pref = In_file

 

*  Assign(w, out_file);

*  Rewrite(w);
 

w = FCREATE(Out_file)

IF w < 0

  DO l_err WITH FERROR(), "Cannot create output file " + Out_file

ENDIF

 

*  Alldone := False;

*  Alldone is set to False automatically in above LOCAL declaration

 

*  file_no:=0;

*  while not alldone do 

*  Begin
 

file_no = 0

DO WHILE NOT Alldone
 

*    file_no:=file_no+1;

*    str(file_no,suffix);

*    while length(suffix)<3 do suffix:='0'+suffix;

 

*    In_file:=In_pref+'.'+suffix;  

*    Assign(f, In_file);
 

  file_no = file_no + 1

  suffix = PADL(file_no, 3, '0')

  In_file = In_pref + '.' + suffix

  

*    {$I-}

*    Reset(f);

*    {$I+}

*    If IOResult<>0 then

*    begin

*      Alldone:=True;

*      if suffix='001' then 

*      begin

*        write('File ',in_file,' not found.');

*        halt;

*      end;

*    end else

    

  f = FOPEN(In_file)

  IF f < 0

    Alldone = .T.

    IF suffix  = '001'

      DO l_err WITH FERROR(), "File " + In_file + " not found."

    ENDIF

  ELSE

  

*    begin  

*      lines:=0;

*      writeln('Reading ', In_file, ' into ',out_file);

*      while not eof(f)  do

*      begin

*        read(f,c);

*        asc:=ord(c);

*        if (asc>9) and (asc<>29) then write(w,c);

* 

*        {if (asc>= 13) and (asc <= 126) then write(w,c);}

*      end;

*      close(f);

*      erase(f);

*    end;

*  end;    
 

    WAIT WINDOW "Reading " + In_file + " into " + Out_file NOWAIT

    

    DO WHILE NOT FEOF(f)

      c = FREAD(f, 1)

      IF ASC(c) > 9 AND ASC(c) <> 29

        = FWRITE(w, c)  && Here we could test return value to catch possible error

      ENDIF

    ENDDO

    

    = FCLOSE(f)

    ERASE (In_file)

    

  ENDIF
 

ENDDO
 

*  Close(w);

*  Writeln('Files combined.');

*end.
 

= FCLOSE(w)

WAIT WINDOW 'Files combined.' NOWAIT
 

RETURN
 
 

*-- Error handling

PROCEDURE l_err

LPARAMETERS lnErrNo, lcErrText, lnLineNo
 

MESSAGEBOX("Error " + ALLTRIM(STR(lnErrNo)) + ' ' + lcErrText + ;

            IIF(!EMPTY(lnLineNo), ', line: ' + ALLTRIM(STR(lnLineNo)), ''), 16)
 

CANCEL

Open in new window

0
 
LVL 8

Expert Comment

by:mikegagnon
ID: 24089567
pcelba

>>>BTW, do you know what was Dbase II+?

It all depends how long you have been programming with the platform. I do know DBase II+, as I have used it, and Foxbase and Foxpro DOS and on and on...(I still has all the diskettes fo all of them)
But as you say it has really nothing to do with the main question here.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 24090838
You have been using DBase II+? That's perfect! On what computer did you use it? Me on TNS.
0
 
LVL 8

Expert Comment

by:mikegagnon
ID: 24091803

>>You have been using DBase II+? That's perfect! On what computer did you use it? Me on TNS

I am not sure this will help the original question. If you have a question on DBase II+ you may want to start you own thread,
0
 
LVL 41

Expert Comment

by:pcelba
ID: 24091950
I don't think it is necessary to open another thread and no zone for DBase II+ is here :-).

This question is solved already and open to discussion. And if we are discussing such dinosaurus like Foxbase and DBase II+ and you are the first person here who used DBase II+ then I cannot be silent because I am highly interested. (Hope you know I am not talking about dBase III+)
0
 
LVL 8

Expert Comment

by:mikegagnon
ID: 24092124
>>>>And if we are discussing such dinosaurus like Foxbase and DBase II+ and you are the first person here who used DBase II+ then I cannot be silent because I am highly interested. (Hope you know I am not talking about dBase III+)

First? No I don't think I am this first, although the other person I am thinking of has passed away (Ed Raugh) . But I did use everything, including dBase II+ and dBase III+, but it has been a longtime, but still the potential of these plateform could be seen back then...and here we are at the end of an era (or two).
0
 
LVL 41

Expert Comment

by:pcelba
ID: 24092374
Thanks for the historic info. I am still saying the end of era will come together with AI. Languages we are using now do not matter, they are just episodes. (I started with Fortran.)

And I agree to close this discussion.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

705 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

19 Experts available now in Live!

Get 1:1 Help Now