I'm wodering how to send email without system(). Can't figure out the way
passing
char *msgbody to /bin/mail in execv() in a linux box. any way to do it or
have to use other command. My boss thinks system() is no good, btw.
TIA
sam
1. Create a pipe using pipe(2)
2. Install a handler to catch SIGCHLD signals to avoid a zombie
3. fork(2)
In the child now do:
4C: close(2) write of pipe
5C: call dup2(2) with the read end of the pipe and STDIN as the
arguments,
6C: call execcv() to replace the childs code by the one of /bin/mail
with the appropriate command line arguments, i.e.
const char *my_args[ 5 ];
my_args[ 0 ] = "/bin/mail";
my_args[ 1 ] = "-s"
my_args[ 2 ] = "The subject line"
my_args[ 4 ] = NULL;
execv( my_args[ 0 ], my_args );
In the parent you do
4P: close(2) the read end of pipe
5P: copy the message using write(2) to the write end of the pipe
6P: close(2) the write end of the pipe
That's basically everything you need. Things would be even simpler
if you are allowed to use popen(3) and pclose(3), then all you
need to call popen() with the mail-command, then write to the
newly created stream and finally close it.
Regards, Jens
--
_ _____ _____
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Get a copy of any good book on UNIX programming. Read the section onQuote:> I'm wodering how to send email without system(). Can't figure out the way
> passing
> char *msgbody to /bin/mail in execv() in a linux box. any way to do it or
> have to use other command. My boss thinks system() is no good, btw.
Comments like "system() is no good" are meaningless. Without citing a
specific problem or type of problem, he could mean that 'system()' is no
good for frying eggs.
DS
1. lpd: cannot execv .. printer filters
Slackware 4.0 setup right off the CD, 2.0.6 kernel.
Firstly, I've been running a Linux box for very long time and am
neither blushing virgin nor newbiw. Nevertheless I can't get lpd
filters to work.
The lpd system works fine when sending "raw" files to the printer..
provided I don't have an if: filter in printcap. When I do, I'm
seeing the following in the syslog:
Jun 23 18:23:08 musica lpd[354]: cannot execv /var/spool/lp1/test/input_filter
What am I looking for???
Here's the relevant printcap entry:
test|testnec:\
:lp=/dev/null:\
:sd=/var/spool/lp1/test:\
:lf=/var/spool/lp1/test/errs:\
:if=/var/spool/lp1/test/input_filter:\
:mx#0:\
:sh:
Here are the relevant spooler permissions:
drwx------ 2 root lp 1024 Jun 23 18:23 test/
/var/spool/lp1/test:
total 3
-rw-r--r-- 1 root lp 18 Jun 23 18:23 lock
-rw-rw-r-- 1 root lp 27 Jun 23 18:23 status
-rwxr-xr-x 1 root lp 222 Jun 22 19:19
input_filter*
-rw-r--r-- 1 root lp 0 Jun 19 12:40 errs
Here is input_filter:
#/bin/sh
echo ------------------------------- >>/tmp/test.nec
date >>/tmp/test.nec
echo ------------------------------- >>/tmp/test.nec
cat >>/tmp/test.nec
Obviously this is a trivial filter.. makes no difference, I get
that same "cannot execv" error in syslog.
What am I looking for?
--
Richard J. Wyble
2. Can you create your own custom boot floppy?
3. setting environment before calling execv()
5. Print filter error: lpd[10296]: cannot execv
6. RedHat finds SB16 but not AWE
8. how do I open tektronix window on AIX3.1 ?
9. Memory allocation and execv
10. C++ - Alternatives for execv() & friends
11. cannot execv /var/spool/lpd filter
12. please, urgent, EXECV, how it's running ?!?