On Wednesday 23 November 2011, Andreas Schwab wrote:
> "Steven W. Orr" <[email protected]> writes:
>
> > I think we're beating this one to death, but I have point out that
> > telling perl to run a print command whose output is redirected by bash
> > is not the same as telling bash to run a builtin echo command that is
> > redirected as an integral operation of the same interpreter.
>
> They are really the same, but even if you change it bash still wins:
>
> $ bash -c 'echo "hello"' >/dev/full
> bash: line 0: echo: write error: No space left on device
>
IMO this is not really perl's fault, but rather the programmer's
fault, since he has forgotten to check for possible errors. If
did, he would get:
$ perl -e 'print "hello"; close(STDOUT) or die "$!\n";' >/dev/full
No space left on device
$ echo $?
28
Something similar happens with C, of course, if you forget to check
error conditions:
$ cat > foo.c <<'END'
#include <stdio.h>
int main (void)
{
printf("hello\n");
return 0;
}
END
$ gcc foo.c
$ ./a.out >/dev/null # Oops, no error reported.
$ cat > foo.c <<'END'
#include <stdio.h>
int main (void)
{
printf("hello\n");
if (fclose(stdout) != 0)
perror("Write error");
return 0;
}
END
$ gcc foo.c
$ ./a.out >/dev/null # Error will be reported now.
Write error: No space left on device
More "modern" languages, with built-in exception handling, are somewhat
better in this regard:
$ python3 -c 'print("foo")' >/dev/full
Exception IOError: (28, 'No space left on device') in ... ignored
Just my 2 cents.
Regards,
Stefano