I compiled the following code with gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) under Ubuntu 10.04 LTS.
user@ubuntu:~/doc$ cat simple_write.c
#include <unistd.h>
#include <stdlib.h>
int main()
{
if ((write(1, "Here is some data\n", 18)) != 18)
write(2, "A write error has occurred on file descriptor 1\n",46);
exit(0);
}
user@ubuntu:~/doc$ ./simple_write
Here is some data
Can someone explain to me why the second error message is not printed?
Is it redirected to other place? Then, how to make it show up?
Thank you
The second message doesn’t show up because the first
write()successfully wrote 18 characters.To demonstrate, change
!=into==.