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

How do I write scripts that will write to the command line both directly to initiate programs and then to write input for the program when prompted in the command line?

Replies are listed 'Best First'.
Re: Command Line Programming
by ides (Deacon) on Jun 20, 2002 at 16:00 UTC
    You can call other programs from within your program with the system() function or by using back ticks ``.

    As for being able to read/write to the program you have called you'll want to take a look at the documentation for open(), open2(), and open3() depending on what you are trying to accomplish.

    If you could give us some more detailed information we'd be able to help you further.

    -----------------------------------
    Frank Wiles <frank@wiles.org>
    http://frank.wiles.org

Re: Command Line Programming
by r0b (Pilgrim) on Jun 20, 2002 at 16:16 UTC
    To write to a program use the following:
    $pid = open(PROG, "| /path/to/program"); print PROG "input for prog"; close(PROG);

    ~~rob
    ____________________________________________________________
    eval pack "h*", "072796e647022245d445f475454494c5e622b3";

      And obviously if you wanted cmd line arguments just add them to the exe line below.
      $pid = open(PROG, "| /path/to/program -a v1 -b v2 "); print PROG "input to program\n"; close(PROG);
      See IPC::Open2 and IPC::Open3 for reading from STDOUT, STDERR, and writing to STDIN all for the same application.
Re: Command Line Programming
by flounder99 (Friar) on Jun 20, 2002 at 16:18 UTC
    You might want to look at Expect on CPAN. It is also available via ppm if you are using ActivePerl

    --

    flounder