artist has asked for the wisdom of the Perl Monks concerning the following question:

I have a program, which I can run manually and enter values and it generates the logs on the screen. The program is very old and works only this way ie.. no other direct way of running it. Now, I like to automate this. So, I need to write a Perl program, which can invoke the old-program, provide values from the file and write logs to another file.

How do I go about this?

Thanks.

Replies are listed 'Best First'.
Re: Feeding values to an existing program
by Fletch (Bishop) on Mar 17, 2005 at 14:19 UTC

    Somewhat vague problem statement, but sounds like a job for Expect.

Re: Feeding values to an existing program
by dragonchild (Archbishop) on Mar 17, 2005 at 14:38 UTC
    I agree with Fletch - Expect is the way to go. I used it to test a Zork-like text adventure program and it worked great.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: Feeding values to an existing program
by scmason (Monk) on Mar 17, 2005 at 16:34 UTC
    It seems like you could use a piped open to feed values to its standard in and then just redirect it output to a logfile. Something like this:

    open(PROG,"|program > logfile")

    while $data = <DATASOURCE>{

    print PROG $data;

    }

    This will open "program" and redirect its output to "logfile", leaving you with a pipe ti its stdin. You can write to this pipe through the filehandle "PROG"

    The drawback of this approach is that it is not very sophisticated (does your program 'prompt' when it wants input, or does it constantly accept it, expect would help if the former is the case), but the value is that it is simple.