Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
system("echo \"message\" | mail -s \"subject\" example@example.com example2@example.com");
/*
* email to user fred using the Unix pipe
*/
#include <stdio.h>
int main(void)
{
static char *slines[] =
{
"This is the first line of the mail example",
"and this is the second line",
"and of course this is the third"
};
char *com_str="mailx -s \"write a message\" fred";
run_wpipe(slines, 3, com_str);
exit(0);
}
/*
* This function:
* 1) creates a pipe.
* 2) creates another process with fork().
* 3) couples standard input to the reading end of the pipe
* using the dup() call.
* 4) closes file descriptors.
* 5) executes the child process.
* 6) closes the read side of the pipe.
* 7) opens the write side of the pipe using fdopen().
* 8) writes the number of input lines.
* 9) closes the file pointer.
*
* lineptr is an array-of-pointers where each element is a string
* to be written to the pipe.
*/
int run_wpipe(lineptr, nolines, exe_str)
char *lineptr[]; /*array-of-pointers to strings */
int nolines; /*number of lines to write */
char *exe_str; /*pipe command */
{
int i, p[2], pid;
FILE *ptr, *fdopen();
if(pipe(p) < 0)
fatal("pipe call");
switch(pid=fork())
{
case -1:
fatal("fork call in run_wpipe");
case 0:
close(0); /*close the standard input */
dup(p[0]); /*read side of the pipe */
close(p[0]); /*save the file descriptors */
close(p[1]);
execlp("/bin/sh", "sh", "-c", exe_str, NULL);
fatal("exec call in run_wpipe");
}
close(p[0]); /*close the read side of the parent */
if((ptr=fdopen(p[1],"w")), ptr == NULL)
fatal("fdopen call in run_wpipe");
for(i = 0; i<nolines; i++)
fprintf(ptr,"%s\n", lineptr[i]);
fclose(ptr);
/*wait for child process to finish*/
while(wait((int *)0) != pid)
;
}
int fatal(str)
{
printf("%s\n");
exit(1);
}
/*
* email to user fred using the Unix pipe
*/
#include <stdio.h>
int main(void)
{
static char *slines[] =
{
"This is the first line of the mail example",
"and this is the second line",
"and of course this is the third"
};
char *com_str="mailx -s \"write a message\" fred";
run_wpipe(slines, 3, com_str);
exit(0);
}
/*
* This function:
* 1) creates a pipe.
* 2) creates another process with fork().
* 3) couples standard input to the reading end of the pipe
* using the dup() call.
* 4) closes file descriptors.
* 5) executes the child process.
* 6) closes the read side of the pipe.
* 7) opens the write side of the pipe using fdopen().
* 8) writes the number of input lines.
* 9) closes the file pointer.
*
* lineptr is an array-of-pointers where each element is a string
* to be written to the pipe.
*/
int run_wpipe(lineptr, nolines, exe_str)
char *lineptr[]; /*array-of-pointers to strings */
int nolines; /*number of lines to write */
char *exe_str; /*pipe command */
{
int i, p[2], pid;
FILE *ptr, *fdopen();
if(pipe(p) < 0)
fatal("pipe call");
switch(pid=fork())
{
case -1:
fatal("fork call in run_wpipe");
case 0:
close(0); /*close the standard input */
dup(p[0]); /*read side of the pipe */
close(p[0]); /*save the file descriptors */
close(p[1]);
execlp("/bin/sh", "sh", "-c", exe_str, NULL);
fatal("exec call in run_wpipe");
}
close(p[0]); /*close the read side of the parent */
if((ptr=fdopen(p[1],"w")), ptr == NULL)
fatal("fdopen call in run_wpipe");
for(i = 0; i<nolines; i++)
fprintf(ptr,"%s\n", lineptr[i]);
fclose(ptr);
/*wait for child process to finish*/
while(wait((int *)0) != pid)
;
}
int fatal(str)
{
printf("%s\n");
exit(1);
}
{"mail from:", "rcpt to:", "data:", "\r\n.\r\n"};