[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: process substitution

From: Marc Herbert
Subject: Re: process substitution
Date: Thu, 15 Oct 2009 11:44:28 +0100
User-agent: Thunderbird (X11/20090320)

> On Mon, Oct 12, 2009 at 1:14 PM, Ralf Goertz
>> is it possible to have a process substitution with both input and output
>> redirection? So far I use the following work-around
>>> cat parentprocess.sh:
>> #!/bin/bash
>> mkfifo fifo 2>/dev/null
>> exec 5> >(./subprocess.sh > fifo)
>> exec 6< <(cat < fifo)

I think "exec 6<fifo" is enough here?

>> Is there another way to do that, something like fork, which wouldn't use
>> a named pipe explicitely?

"socat" provides a terse solution where you still have to name the
pipes, but their clean-up comes for free. Moreover it works with any

socat is very flexible, below is only one of the ways to do it.


socat EXEC:./subprocess.sh  PIPE:tosub.$$,nonblock!!PIPE:fromsub.$$    &

# The alternative to polling is creating the pipes in
# advance. But this would require a "finally" clause to clean them.
until test -p fromsub.$$; do sleep 1; done

exec 6<fromsub.$$
exec 5>tosub.$$

echo input to subprocess 1>&5
echo done sending input
# [etc.]

reply via email to

[Prev in Thread] Current Thread [Next in Thread]