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

Using the 'system' function I call an exe from perl script. That exe may throw a error window with options 'Abort/Retry/Ignore'. I have to select any one of these option through the same perl script itself automatically. How to do it?
  • Comment on Handling third party exe messages through perl script?

Replies are listed 'Best First'.
Re: Handling third party exe messages through perl script?
by eibwen (Friar) on May 12, 2005 at 06:00 UTC

    Use a bidirectional open to pipe in the output and when the prompt is encountered, merely print:

    use IPC::Open2; my $pid = open2(*OUTPUT, *INPUT, "program.exe"); while (my $line = <OUTPUT>) { print INPUT 'f' if /Abort\/Retry\/Ignore/; }

    Be sure to read more about bidirectional IPC, in perlfunc under open and perlipc. The above is merely an example -- the referenced perldoc describe the IPC is considerable detail and are recommended reading.

      Note however, that some programs need a tty for interaction and them the open2 may fail. In that case, Expect may come to the rescue.

      Paul

Re: Handling third party exe messages through perl script?
by eXile (Priest) on May 12, 2005 at 13:59 UTC
    Don't think Expect will work in such a situation, because you'd have to react to an error window, not an error message that can be caught by expect.

    After some searching on CPAN found this: Win32::CtrlGUI which sounds promissing as a way to control any window that pops up.

    HTH

Re: Handling third party exe messages through perl script?
by thcsoft (Monk) on May 12, 2005 at 04:21 UTC
    hmm... i'm not firm with windows, but on a linux box i'd suggest you install a hook for a certain signal.

    language is a virus from outer space.