[asterisk-dev] Module to Asterisk function Compiler Issue question

Tilghman Lesher tilghman at meg.abyt.es
Mon Aug 8 08:15:04 CDT 2011


On Sunday 07 August 2011 21:20:10 Mike Myhre wrote:
> > It's doing exactly what the exec() family of functions is supposed to
> > do; replace the current executable image in the process with a
> > different one and then execute it. If you want to execute the shell
> > script in a child process, you have to fork() first... but you'd be
> > better off to use ast_safe_system() which handles quite a few other
> > nasty details for you as well.
> 
> I have one more question on the ast_safe_system() function and child
> processes. Is there a simple way to get output from a shell script? My
> CLI command has an open file descriptor I want to write to (a->fd) that
> should be open in my child process. I tried passing the file descriptor
> as a command argument and using it in a shell script, but I get the "Bad
> file descriptor" message on stderr output. I could write to a temporary
> file and read the file from my res module, but that isn't a very clean
> solution.
> 
> Is there a preferred way to get output from shell scripts to the
> asterisk CLI?

Your best bet is to use dup2() to re-channel the output of that subprocess
to the STDOUT_FILENO (2), after the fork() (or ast_safe_fork(), in versions
which support that API), but before the exec().

-- 
Tilghman



More information about the asterisk-dev mailing list