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

I'm running Activestate perl 5.6.1. I have a DOS application that resembles a dos shell (call it app.exe). It is my task to write a perl program to operate app.exe. I'm having some grief, though, and am turning to the illustrious monks for help. From what I've read, pipes sound like what I need. I've created a little code to test them out before I get hot and heavy in it.
open(TEST, "| app.exe"); sleep 3; print(TEST "the -command");
This is starting app.exe as I see the text app.exe spits out on startup. But it ends up in GetConsoleMode failed error. Any ideas? Many thanks.

Replies are listed 'Best First'.
Re: pipes on NT
by Solo (Deacon) on Feb 05, 2003 at 22:58 UTC
    Here are some things to try:

    What happens if you try to pipe to app.exe from the command line? e.g.

    echo the -command | app.exe

    What happens if you add a cmd to your open? e.g.

    open(TEST, "| cmd.exe app.exe");
    --
    You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.
      The tricky part is that app.exe starts a console application (in effect becomes a new shell). app.exe does not accept just any command. You have to wait till it starts, then enter your commands.

      As to your suggestions, I get the same error when piping from command line. I believe that app.exe is not set up to accept input from pipes.

      Good news is that I found the code for app.exe. So now I get to figure out whats going on in there (written in C). Ah, what a slippery slope. ;D

      Thanks for the input!
        As to your suggestions, I get the same error when piping from command line. I believe that app.exe is not set up to accept input from pipes.
        That's the intention of the test. ;)

        Best of luck!

        --
        May the Source be with you.

Re: pipes on NT
by John M. Dlugosz (Monsignor) on Feb 05, 2003 at 21:22 UTC
    I've never had that problem. But here's a clue: look up GetConsoleMode in a win32 API reference, and see under what the preconditions are.
      Well, I've written a small test program to use instead of app.exe. The pipe seems to work. So the problem must be that app.exe does something goofy. If anyone has any workaround ideas, by all means, fire away. /me wonders why things must be so difficult.