Need script to redirect STDIN & STDOUT to named pipes

Posted by user54903 on Server Fault See other posts from Server Fault or by user54903
Published on 2010-10-04T01:34:45Z Indexed on 2011/01/06 17:55 UTC
Read the original article Hit count: 496

I have an app that launches an authentication helper (my script) and uses STDIN/STDOUT to communicate.

I want to re-direct STDIN and STDOUT from this script to two named pipes for interaction with another program.

E.g.:

SCRIPT_STDIN > pipe1
SCRIPT_STDOUT < pipe2

Here is the flow I'm trying to accomplish:

[Application] -> Launches helper script, writes to helpers STDIN, reads from helpers STDOUT (example: STDIN:username,password; STDOUT:LOGIN_OK)
[Helper Script] -> Reads STDIN (data from app), forwards to PIPE1; reads from PIPE2, writes that back to the app on STDOUT
[Other Process] -> Reads from PIPE1 input, processes and returns results to PIPE2

The cat command can almost do what I want. If there were an option to copy STDIN to STDERR I could make cat do this with a command (assuming the fictitious option -e echos to STDERR rather than STDOUT):

cat -e PIPE2 2>PIPE1 (read from PIPE2 and write it to STDOUT, copy input, normally going to STDERR to PIPE1)

© Server Fault or respective owner

Related posts about named-pipes

Related posts about shell-scripting