Program to Program communication?

Program to Program communication?

Post by srhad.. » Tue, 02 Nov 1999 04:00:00



I have one ksh script that calls a perl script.  I want these programs
to communicate with eachother.  I basically want the perl script to
respond with a yes or no.  I suppose one would think to just use the
exit code of the perl script, but the exit code is reserved for when the
perl script is called by itself.

Thanks for any guidance in this.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Program to Program communication?

Post by Eric Amic » Tue, 02 Nov 1999 04:00:00



> I have one ksh script that calls a perl script.  I want these programs
> to communicate with eachother.  I basically want the perl script to
> respond with a yes or no.  I suppose one would think to just use the
> exit code of the perl script, but the exit code is reserved for when the
> perl script is called by itself.

You might consider co-processes.  The following illustrate how you can
interact with a co-process:

perlscript |&    # Run perlscript in background as co-process

read -p line     # Read line of data from co-process

print -p whatever   # Write data to co-process

exec 3<&p 4>&p   # Connect file descriptors 3 and 4 as input from and
                 # output to co-process, respectively

--
Eric Amick
Columbia, MD


 
 
 

Program to Program communication?

Post by brian hile » Tue, 02 Nov 1999 04:00:00




> ...
> perlscript |&    # Run perlscript in background as co-process
> read -p line     # Read line of data from co-process
> print -p whatever   # Write data to co-process

You've got the read and write backwards. The read will block until
the write will fill the coprocess pipe (which will never happen,
of course.)

print -p whatever
read -p line

Quote:> exec 3<&p 4>&p   # Connect file descriptors 3 and 4 as input from and
>                  # output to co-process, respectively

This is academic, as the coprocess has already been written/read from.
Perhaps an explanation that coprocess I/O can be redirected as per files?

perlscript |&
exec 3<&p 4>&p
print whatever >&4
read line <&3            # I would suggest the -r option to read as well...

Overall, though, you gave the best advice for the particular problem.

-Brian