你好 agapanthus,
[… Ausgabe umleiten …]
Kann mir einer auf die Sprünge helfen?
Eigentlich sehr einfach: vor dem fork() einen pipe()-Aufruf machen. Dann
im Kind _vor_ dem execve() per dup2() den stdout-Deskriptor in die Pipe
umleiten:
int main(void) {
int fds[2],status;
pid_t p;
if(pipe(fds) == -1) {
perror("pipe");
return EXIT_FAILURE;
}
if((p = fork()) == -1) {
close(fds[0]);
close(fds[1]);
perror("fork");
return EXIT_FAILURE;
}
if(p == 0) {
if(dup2(fileno(stdout),fds[1]) == -1) {
perror("dup2");
close(fds[0]);
close(fds[1]);
return EXIT_FAILURE;
}
execve(...);
close(fds[0]);
close(fds[1]);
perror("execve"); /* only reached if an error occures */
return EXIT_FAILURE;
}
/* hier von fds[0] die Ausgabe des Programms lesen */
waitpid(p,&status,0);
if(WEXITSTATUS(status) != EXIT_SUCCESS) {
close(fds[0]);
close(fds[1]);
return EXIT_FAILURE;
}
/* mach was mit der Ausgabe */
close(fds[0]);
close(fds[1]);
return EXIT_SUCCESS;
}
So müsste es passen. Typos kannst du behalten ;)
再见,
克里斯蒂安
--
Meine Schultüte | Nein, es ist nicht das Fenster…
On the day *I* go to work for Microsoft, faint oinking sounds will be heard from far overhead, the moon will not merely turn blue but develop polkadots, and hell will freeze over so solid the brimstone will go superconductive. (Eric Raymond als Antwort auf ein Job-Angebot von MS)
http://wwwtech.de/
Meine Schultüte | Nein, es ist nicht das Fenster…
On the day *I* go to work for Microsoft, faint oinking sounds will be heard from far overhead, the moon will not merely turn blue but develop polkadots, and hell will freeze over so solid the brimstone will go superconductive. (Eric Raymond als Antwort auf ein Job-Angebot von MS)
http://wwwtech.de/