I am trying to write a wrapper to invoke a script which takes input from
STDIN.

I am opening a filehandle so that I can store all information returned by
invoked script.

However, it hangs when second script is waiting for user input.  Input
varies from time to time.

So, I can't use open(SCRIPT, "| @cmd ") and send values to SCRIPT. Is there
any way I can make sure second program gets input from user and store all
information in array or somewhere I can use for sending in email?

Thanks for your help in advance.


sub executeScript {

        my (@cmd) = @_;

        my $status = 0;

        my $comment = "\nRunning " . join(" ", @cmd) . " ...\n";
        push(@msg, $comment);


        my $pid = open(SCRIPT, " @cmd |") or die "Couldn't run @cmd: $!\n";

        while (<SCRIPT>) {
        #add STDOUT or STDERR from script being run to @msg for email output

                chomp;
                push (@msg, $_);
        }

       unless(close(SCRIPT)) {
                $status = 1;
                push(@msg, "@cmd failed\n");
        }
        return $status;
}

Reply via email to