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

Hi, I have the perl script "cli.pl". After executed this script it's waiting for inputs from commandline same as our UNIX Shell... for each cli command this script will respond.. and waiting for next cli input command... This is behavior of cli.pl... Now i want to test(automate) the cli.pl using another script say "auto.pl" From auto.pl i want start the execution of "cli.pl" then wait sometime to execute and pass the arguments to the cli.pl and get back the result and store it in one file.... Plz help me .... to my problem..
  • Comment on How to redirect STDIN and STDOUT to the particular perl script

Replies are listed 'Best First'.
Re: How to redirect STDIN and STDOUT to the particular perl script
by Tanktalus (Canon) on Dec 23, 2005 at 16:44 UTC

    Check out IPC::Run2 or IPC::Run3 (I use the latter even when I don't care about STDERR).

    If you're really tricky, you can run your cli.pl with IPC::Run#, then fork off a reader that reads the STDOUT and saves to disk leaving your initial process to write to cli.pl without ever having to worry about blocking.

      Hi..,

      As you have suggested, currently i'm using IPC::Run module to redirect the STDIN and STDOUT of the particular perl script. In this i'm getting some issues..here is some sample code..

      my $h = start \@cat, \$in_q, '>>', "out.txt", '2>>', "err.txt", debug + => 0 ; $in_q = "help\n" ; pump $h; $in_q = "lscomp\n"; pump $h; finish $h or die "cat returned $?" ;
      Issue: After "pump" the all the inputs and "finish" it only...i will get the result for all the inputs....But i need immediate result (response) for every "pump" operation .... In my case for each input, the output have more than 10 lines of response...

      So please ..can you help me for my problem.....!

      jdporter added missing markup

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: How to redirect STDIN and STDOUT to the particular perl script
by planetscape (Chancellor) on Dec 23, 2005 at 22:37 UTC
Re: How to redirect STDIN and STDOUT to the particular perl script
by sub_chick (Hermit) on Dec 23, 2005 at 18:52 UTC
    If I am understanding your question correctly, you may want to check out Take file A , translate it, place in new file. I had a question fairly similar to yours and I found GrandFather's code to do just the job I was looking for.

    "Es gibt mehr zu Leben als Bücher, kennen Sie. Aber nicht viel mehr " -(Der Smiths)