[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: exit status issue
From: |
Stefano Lattarini |
Subject: |
Re: exit status issue |
Date: |
Wed, 23 Nov 2011 10:49:33 +0100 |
User-agent: |
KMail/1.13.7 (Linux/2.6.30-2-686; KDE/4.6.5; i686; ; ) |
On Wednesday 23 November 2011, Andreas Schwab wrote:
> "Steven W. Orr" <steveo@syslang.net> 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
- Re: exit status issue, (continued)
- Re: exit status issue, Dallas Clement, 2011/11/22
- Re: exit status issue, Greg Wooledge, 2011/11/22
- Re: exit status issue, Dallas Clement, 2011/11/22
- Re: exit status issue, Greg Wooledge, 2011/11/22
- Re: exit status issue, Bob Proulx, 2011/11/22
- Re: exit status issue, Dallas Clement, 2011/11/22
- Re: exit status issue, Bob Proulx, 2011/11/22
- Re: exit status issue, Dallas Clement, 2011/11/22
- Re: exit status issue, Steven W. Orr, 2011/11/22
- Re: exit status issue, Andreas Schwab, 2011/11/23
- Re: exit status issue,
Stefano Lattarini <=
- Re: exit status issue, Dallas Clement, 2011/11/23
- Re: exit status issue, Greg Wooledge, 2011/11/23
- Re: exit status issue, Andreas Schwab, 2011/11/18