Reputation: 3208
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
printf("hello dude\n");
//cause segfault
*(int*)0 = 0;
return 0;
}
gcc test.c -o test
./test &> out.txt
Segmentation fault (core dumped)
./test > out.txt
Segmentation fault (core dumped)
./test 1> out.txt
Segmentation fault (core dumped)
Open the text file and "hello dude" is never written. If you comment out the line that causes the segfault then "hello dude" gets written to the file. Some how the segfault is interrupting stdout. Is there something that can be on the command line to capture the output? I tried both cygwin bash and linux bash shells.
Upvotes: 1
Views: 1315