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

Hi All,
I am stuck because I have to run a tool using a perl script and it asks for user name and reason for running it.But I am not able to pass these arguments to my script.I have used IPC (Open2 and pipes).Please suggest me how to accomplish this.This is how my tool runs from command prompt -
root@c001n03 ICtool# perl IC4.pl --full
User name : abhinav
Reason for running IC tool: testing

Here is my rough part of code through which I am trying to run this tool -
use IPC::Open2; my $pidSsh = open2($RDR,$WTR,"perl /mnt/1/service/ICtool/IC4.pl --full +"); print "Just for debugging :third line\n"; my $line1 = <$RDR>; print $line1; print $WTR "Abhinav \n" if ($line1 eq "User name :"); my $line2 = <$RDR>; print $line2; print $WTR "Testing \n" if ($line2 eq "Reason for running IC tool:");
The script is going to the third line where it is printing "Just for debugging :third line".But it is not asking for the User name and reason.So the tool is not getting executed using this script.Please suggest me how do I proceed.
I tried to implement the suggestions of the revered monks.Even if I dont read anything from the read handle (just write the user name and reason to the write handle) even then program does not run.So problem cant be solved with changing input record separator.I am using PERL Version 5.8.3 which does not have Expect.pm .What else can I do with the current version for the script to run?

Replies are listed 'Best First'.
Re: Cannot read from STDIN and write to STDOUT using IPC and pipes
by moritz (Cardinal) on Oct 11, 2007 at 08:12 UTC
    I think the problem is that the line my $line1 = <$RDR>; tries to read until the next input record separator, which is usually a newline.

    The program's output doesn't seem to have a newline.

    You could try to use Expect.pm or something along these lines, or change $/ to ':' (or whatever your program uses to terminate the prompt)

      I tried to implement your suggestions.Even if I dont read anything from the read handle (just write the user name and reason to the write handle) even then program does not run.So problem cant be solved with changing input record separator.I am using PERL Version 5.8.3 which does not have Expect.pm .What else can I do with the current version for the script to run?
        The language is called Perl, the interpreter perl. But what is PERL?

        If Expect is not available, you can install it from cpan.

Re: Cannot read from STDIN and write to STDOUT using IPC and pipes
by Somni (Friar) on Oct 11, 2007 at 08:16 UTC
    Based on your description the program you're using (IC4.pl) is either displaying directly to the terminal, or expecting input from the terminal, instead of the normal STDOUT and STDIN. The typical solution to dealing with interactive programs like this is to use Expect.