Witam,
Miałem za zadanie uzupełnic częsciowy program, aby za jego pomocą wysłac maila o danej tresci, ktora ma byc brana z potoku
Wszytsko super tylko mail jakiego otrzymuje nie ma treści ;/ Co zrobiłem nie tak?
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#define EMAIL "[email protected]"
int shellcmd(char *command) {
int status;
pid_t pid;
extern int errno;
if ((pid = fork()) < 0) {
status = -1;
}
if (pid == 0) {
execl("/bin/sh", "sh", "-c", command, NULL);
_exit(127);
}
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR) {
status = -1;
break;
}
}
return status;
}
void sendmail() {
char command[255];
sprintf(command, "echo '' | mail -v -s 'Message from process PID %d' %s", getpid(), EMAIL);
printf("%s\n", command);
shellcmd(command);
}
int main () {
int fd[2];
pid_t pid;
pipe(fd);
pid = fork();
sendmail();
if (pid == (pid_t) 0) {
/* child */
close(fd[1]);
dup2(fd[0], STDIN_FILENO);
close(fd[0]);
execlp("sort", "sort", 0);
} else if (pid > 0) {
FILE * stream;
close(fd[0]);
strumien = fdopen(fd[1], "w");
fprintf(stream, "Witam.\n");
fflush(stream);
close(fd[1]);
waitpid(pid, NULL, 0);
} else {
fprintf(stderr, "can't open child process\n");
}
return 0;
}