LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   process substitution (https://www.linuxquestions.org/questions/linux-software-2/process-substitution-261419/)

jk3us 12-01-2004 02:36 PM

process substitution
 
Bash supports process substitution. This allows you to open a file descriptor for either standard in or standard out for a process. For example, I can open fd 9 to read the output of the ls command:
Code:

exec 9< <(ls)
Now I can
Code:

read -u 9
or redirect that fd into another process:
Code:

cat <&9
.
I can do that with stdin as well
Code:

exec 9> >(cat)
My question is... is it possible to open two file descriptors for the process that represent stdin and stdout, so you can write to one, and get the result from the other? Right now, I'm accomplishing the same effect using named pipes for one end and a file descriptor for the other, but then you have to worry about cleaning up your temporary fifos and it's much less secure. Any suggestions?

jk3us 12-02-2004 04:34 PM

To Answer my own post... It looks like this is not possible in bash. It is however possible in zsh (and some others) with the coproc builtin. So, you can....

# start zsh
bash $ zsh
# start coproccess
zsh $ coproc somecommand_or_pipeline
# redirect its stdin and stdout to numbered fds
zsh $ exec 6>&p 7<&p
# run bash again, and the fd's get inherited
zsh $ bash
bash $


All times are GMT -5. The time now is 11:22 PM.