Redirect STDOUT from a Unix script to a perl program and then redirect back to script 
Author Message
 Redirect STDOUT from a Unix script to a perl program and then redirect back to script

I have a shell script that prompts for input and then reads the input

I want to automate a script by redirecting the prompts to a perl script,
which will decide the correct response, and then send the response back
to the shell script

I thought I could just do something like
"stub | perl res.pl" and when res.pl writes back out to STDOUT via "print"
then "stub" will pick it up with it's "read" but this isn't the case.

Any help is appreciated.

shell script: stub
-------------------------
#!/bin/sh
echo "enter name "
read name
echo "enter phone "
read phone

perl script: res.pl
---------------------------
#!/usr/bin/perl
$input = <STDIN>;
#some logic here to determine the correct response
print $response

-----------------------------



Sat, 01 May 2004 22:41:29 GMT  
 Redirect STDOUT from a Unix script to a perl program and then redirect back to script

Quote:

>I have a shell script that prompts for input and then reads the input

>I want to automate a script by redirecting the prompts to a perl script,
>which will decide the correct response, and then send the response back
>to the shell script

>I thought I could just do something like
>"stub | perl res.pl" and when res.pl writes back out to STDOUT via "print"
>then "stub" will pick it up with it's "read" but this isn't the case.

>Any help is appreciated.

I don't think that sort of circular pipe works.  Most folks on this
list will advise you to port your whole shell script to perl, but if
you're attached to the script, why don't you just invoke perl from
within the script, and then have perl look for command-line args
rather than reading from stdin:

Quote:

>shell script: stub
>-------------------------
>#!/bin/sh
>echo "enter name "
>read name
>echo "enter phone "
>read phone

response=`perl res.pl $name $phone`
# use the response

Quote:
>perl script: res.pl
>---------------------------
>#!/usr/bin/perl


Quote:
>#some logic here to determine the correct response
>print $response

>-----------------------------

--
Mike


Sat, 01 May 2004 23:04:27 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How get back redirected STDOUT to its default?

2. Redirect stderr to stdout w/ Perl under Unix?

3. Redirect stderr to stdout inside perl script

4. redirect STDOUT of entire program?

5. Redirect STDOUT to a program?

6. redirect script just providing an HREF, not redirecting as I'd like

7. cgi script - redirecting a file to STDOUT

8. Cant redirect stdout from CGI script Help

9. how to redirect STDOUT in Perl

10. Redirect output back to console

11. Redirect back to calling page

12. Redirecting STDERR to file then back to terminal?

 

 
Powered by phpBB® Forum Software