Also eine Ausgabe leitet man anders um. Schließe den Filedescriptor 1 und öffne (nach 1) die serielle Schnittstelle. Siehe:
Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
int main() {
if (close(1) != 0) {
perror("close(1)");
return EXIT_FAILURE;
}
int fd = open("/dev/pts/0", O_WRONLY);
if (fd == -1) {
perror("open(\"/dev/pts/0\", O_WRONLY)");
return EXIT_FAILURE;
}
if (fd != 1) {
fprintf(stderr, "wasn't opened as 1 (stdout) but as %d\n", fd);
}
// now all output to stdout is in fact written to /dev/pts/0
printf("this should be on /dev/pts/%d\n", 0);
puts("this as well");
write(1, "and this", 8);
fputc('\n', stdout);
return EXIT_SUCCESS;
}
Hier habe ich das erste virtuelle Terminal statt der Seriellen Schnittstelle geöffnet (ich hab denk ich gar keine mehr, will nicht hinter den PC kriechen, jedenfalls finde ich nix passendes in /dev und ich könnt so das Prog. auch nicht testen, hab nix das den Output der Schnittstelle ließt).
Lesezeichen