1

I am an Informix 4GL developer. Due to maintainability I was tasked to write a wrapper to automate some tasks on a 4GL forms based command line application.

Does anyone have any idea how this can be done on python ? (I‘ll take other languages too but Python is my go to).

My idea was using „keyboard“ to simulate key presses...(ugly I know).

Problem is that, as i had suggested, to rewrite the entire application in python or another language does not fly with my boss. (The application is about 30years old, so are the dbs...it’s messy)

Karl
  • 146
  • 1
  • 1
  • 12
  • Check if one of these [`[python] [informix]`](https://stackoverflow.com/questions/tagged/python+informix) met your needs. – stovfl Mar 22 '19 at 20:23
  • 1
    To the extent that I4GL programs are curses-based (a non-standard version of curses, but still curses-based), you can consider using tools like `expect` (or their Python equivalent) to interact with the I4GL program. It won't be fun, though, writing a program to do that, even with support from an `expect`-like package. It doesn't much matter which language you use the `expect`-like code from — I'm assuming there is such a package for Python; there is for Perl. Also, are you using the (long dead) product Informix 4GL Forms, or are you using generic forms as found in I4GL programs? – Jonathan Leffler Mar 22 '19 at 23:22
  • 2
    Do you have the source code? Can you compile the source code? Have you considered using command line arguments instead of curses-based input to drive the programs? That might be easier to manage. Some code changes required, but probably a lot easier than writing a program pretending to be a human at a keyboard. – Jonathan Leffler Mar 22 '19 at 23:23
  • @stovfl thanks, but most of that is python talking Informix db not forms. – Karl Mar 23 '19 at 21:08
  • 1
    @JonathanLeffler yeah they have an expect lib for python sadly it won’t do here because as you guessed I am using the long long dead product Informix 4GL forms and you have to navigate it with left right key and esc to confirm selection , I am not aware of a way to just pass arguments. I will ask if I can make those changes to the 4GL source code to run it with command line arguments (I do have the source code and I can compile it). I see it being the o my solution as ugly keyboard input simulation. – Karl Mar 23 '19 at 21:15
  • Thanks for confirming I4GL Forms vs forms in I4GL. The Python Expect module should be able to send left arrow, right arrow and escape codes cleanly — that is one of its jobs. But life won't be easy working out which of those to send at any given point. There isn't a good solution outside of a complete rewirte, IMO. But the rewrite will be a major exercise in its own right. – Jonathan Leffler Mar 23 '19 at 21:22
  • @JonathanLeffler i think you got me on the right track, i am using pexpect (Python expect lib) and pxssh to hack my way around. I am able to read some stdout so i can kind of figure out where I am in the program. – Karl Mar 25 '19 at 06:28

1 Answers1

2

20 years ago I had cron-jobs setup as

    fglgo program-name < keystrokes.txt

where keystrokes.txt was as the name suggests was simply the keystrokes as required to be typed in to run the program manually. This was typically used to generate reports or kick off batch processes in the middle of the night.

A quick text with Four Js Genero suggests that the same principal still works. My little test program was

    #! keystroketest.4gl
    MAIN
    DEFINE where_clause CHAR(100)
        OPEN FORM f FROM "keystroketest"
        DISPLAY FORM f
        MENU ""
            COMMAND "Query"
                CONSTRUCT BY NAME where_clause ON field1, field2, field3
                DISPLAY where_clause
                EXIT MENU
        END MENU
    END MAIN

    #! keystroketest.per
    SCREEN 
    {
    Field 1  [f01      ]
    Field 2  [f02      ]
    Field 3  [f03      ]
    }
    END
    ATTRIBUTES
    f01 = formonly.field1;
    f02 = formonly.field2;       
    f03 = formonly.field3;


    od -x keystroketest.txt
    0000000      3151    3030    0d1b    000a                                
    0000007

    fglrun keystroketest < keystroketest.txt
    field1='100'   

So the keystroketest.txt sends Q (to select Query), 100 (to enter some data into the field), ASCII(27) ie Escape The tricky bit is getting the ASCII(27) into the .txt file.

With FourJs Genero you can still do the above with your Informix-4gl program if you have not added any GUI widgets. If you have added GUI widgets you can also use our automated testing tool (Genero Ghost Client) to execute the 4gl program using a test script to automate it. So if you don't want to rewrite these programs but you want to compile and run them on a modern server etc that might be an option.

fourjs.reuben
  • 286
  • 3
  • 3