On Friday 14 December 2007 19:01, jeff pang wrote:
>
> --- "John W.Krahn" <[EMAIL PROTECTED]> wrote:
> >
> > No, you would have to do:
> >
> > if ( !system($touchcmd) && !system($chkstat) )
>
> I have thought that, if the unix command's author doesn't return a 0
> from the code, how will we get the result of a system command was
> executed successfully or not?
>
> ie, maybe the ppl can return 1 or any other value except 0 from the
> code:
Then that would go against either the "Portable Operating System
Interface" (POSIX) standard[1] or the Single UNIX Specification (SUS)
standard[2]. Even MS-DOS and MS Windows batch files follow the same
convention where 0 is success and not-0 is failure.
> $ cat test.c
> #include <stdio.h>
>
> main () {
In C the main function returns an int so that is not compliant with the
C standard[3]. It should be:
int main ( void ) {
> printf("hello world");
That may not print anything as stdout is buffered. You need to end the
string with a newline to ensure that the buffer is flushed:
printf( "hello world\n" );
> return 1;
Rather than using "magic numbers" you should use the EXIT_SUCCESS or
EXIT_FAILURE macros defined in the stdlib.h[4] header file:
cat /usr/include/stdlib.h
[ SNIP ]
/* We define these the same for all machines.
Changes from this to the outside world should be done in `_exit'. */
#define EXIT_FAILURE 1 /* Failing exit status. */
#define EXIT_SUCCESS 0 /* Successful exit status. */
> }
> When I complied it and run it:
>
> $ ./test
> hello world
>
> then get the value of $?:
>
> $ echo $?
> 1
>
> It's 1 not 0.
> How do you think about this case? :)
I think that anyone with an idea in their head can make a case for any
absurd notion but that does not make it right or standards compliant.
1) http://en.wikipedia.org/wiki/POSIX
2) http://en.wikipedia.org/wiki/Single_UNIX_Specification
http://www.unix.org/version3/
3) http://en.wikipedia.org/wiki/C_(programming_language)
4) http://en.wikipedia.org/wiki/Stdlib.h
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/