C
chrisjroos
Hi,
I have a requirement to create a shell script that accepts data on it's
standard input, calls another shell script (out of my control), passing
an amended copy of the original input, and collects anything sent to
stderr and stdout by the external script. This shell script is to be
used as a mail filter being called from exim.
I got a basic version working using Kernel.open but got very confused
when trying to trap the output of that external script (stderr and
stdout).
The best looking code was produced when using Session[1] but that
started causing me problems too - it looked as though either my parent
or child process didn't wait until the other finished (i.e. i could see
the logged output not following the expected program flow; I fully
expect this to be something I was doing wrong).
I am now using open3 which is working but feels a little fragile,
although that's probably completely unfounded.
I guess I'm really asking for other peoples approaches to similar
problems. My concerns really arise from the fact that I'm not able to
fully test the interaction of this process (or at least not easily).
Does anyone have any tips regarding shell scripting with pipes / forks
/ all the other things I don't really understand?
Chris
[1] http://www.codeforpeople.com/lib/ruby/session/
I have a requirement to create a shell script that accepts data on it's
standard input, calls another shell script (out of my control), passing
an amended copy of the original input, and collects anything sent to
stderr and stdout by the external script. This shell script is to be
used as a mail filter being called from exim.
I got a basic version working using Kernel.open but got very confused
when trying to trap the output of that external script (stderr and
stdout).
The best looking code was produced when using Session[1] but that
started causing me problems too - it looked as though either my parent
or child process didn't wait until the other finished (i.e. i could see
the logged output not following the expected program flow; I fully
expect this to be something I was doing wrong).
I am now using open3 which is working but feels a little fragile,
although that's probably completely unfounded.
I guess I'm really asking for other peoples approaches to similar
problems. My concerns really arise from the fact that I'm not able to
fully test the interaction of this process (or at least not easily).
Does anyone have any tips regarding shell scripting with pipes / forks
/ all the other things I don't really understand?
Chris
[1] http://www.codeforpeople.com/lib/ruby/session/