It is currently Sat, 04 Dec 2021 19:31:17 GMT



 
Author Message
 redirecting _my_own_ output to a pipe
dear All,

I'm trying to write a script that redirects _it's_own_ output to a pipe;
I have been able to do it using a named pipe:

        #! /bin/ash

        [ -p myfifo ] || mkfifo myfifo
        myfilter <myfifo &
        exec >myfifo

        echo hello world
        echo ----
        ps
        echo ----
        echo goodbye world

is there a way to do it using an un-named pipe?

TIA!

--
Otavio Exel /<\oo/>\ oe...@economatica.com.br



 Sat, 19 Jul 2003 19:37:37 GMT   
 redirecting _my_own_ output to a pipe
In article <F455D24F991F56DD.7905B7235780FCD2.8B82AA9FECAF9...@lp.airnews.net>,

(echo hello world
echo ----
ps
echo ----
echo goodbye world) | myfilter

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Sun, 20 Jul 2003 00:30:50 GMT   
 redirecting _my_own_ output to a pipe
On 30 Jan 2001 11:37:37 GMT, oe...@economatica.com.br (Otavio Exel) wrote:

Surely just...

#!/bin/bash
{ echo hello world
        echo ----
        ps
        echo ----
        echo goodbye world

If that is not what you are looking for then please explain exactly why
the above is not sufficient, what are you trying to achieve here?

Bye,

L

- Show quoted text -



 Sun, 20 Jul 2003 04:09:06 GMT   
 redirecting _my_own_ output to a pipe

my problem is the extra shell that is created;
using 'cat' instead of 'myfilter' and 'ps f' instead of 'ps'..

with my named pipe trick I get:

        hello world
        ----
          PID TTY STAT TIME COMMAND
        [snip]
        19828  a0 S    0:01 /bin/bash
        19349  a0 S    0:00  \_ ash ./lixo.sh
        19350  a0 S    0:00      \_ cat
        19351  a0 R    0:00      \_ ps f
        [snip]
        ----
        goodbye world

and with the '(...)|cat' solution I get:

        hello world
        ----
          PID TTY STAT TIME COMMAND
        [snip]
        19828  a0 S    0:01 /bin/bash
        19352  a0 S    0:00  \_ ash ./lixo.sh
        19353  a0 S    0:00      \_ ash ./lixo.sh
        19355  a0 S    0:00      |   \_ ash ./lixo.sh
        19356  a0 R    0:00      |       \_ ps f
        19354  a0 S    0:00      \_ cat
        [snip]
        ----
        goodbye world

this script will run (possibly 24x7) under the control of supervise[1];
supervise provides a confortable way to start and stop whatever it is
controlling;

with the '(...)|cat' trick supervise would stop the script by means of
sending a TERM signal to pid=19352 and leave the others (19353, 19355,
19356 and 19354) running!

hmm.. is there a way to make a script respond to a TERM signal by
killing all it's children before exiting? this would solve my problem!

but I still think it would be nice to be able to do:

        #! /bin/ash
        exec >| myfilter  #(sic)
        echo this
        echo that

thanks a lot!

[1] http://cr.yp.to/daemontools/supervise.html

--
Otavio Exel /<\oo/>\ oe...@economatica.com.br



 Sun, 20 Jul 2003 10:00:37 GMT   
 redirecting _my_own_ output to a pipe

If you use { ... ;} instead of (...) and ksh instead of bash,
it should create no extra processes.

Sure, you can trap SIGTERM:

trap 'child-killer-function' TERM

With ksh you can do it like this:

myfilter |&
exec >&p

--
Tapani Tarvainen



 Mon, 21 Jul 2003 02:17:07 GMT   
 
   [ 5 post ] 

Similar Threads

1. expect: redirect output to a pipe

2. Problem redirecting stdout to pipes/files

3. shell redirect/pipe question

4. pipe and redirect (urgent)!!!

5. Fork/redirect/pipe question (checked faq)

6. is my stdout piped/redirected

7. stdin redirect works, pipe fails

8. redirect stdin/out to unnamed pipe

9. how to redirect stderr through pipe

10. What's the different - pipe vs redirect?


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software