Re: Can't compile this code:
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 11/25/04
- Next message: Chris \( Val \): "Re: Can't compile this code:"
- Previous message: Chris \( Val \): "Re: Pointers"
- In reply to: Alwyn: "Re: Can't compile this code:"
- Next in thread: Alwyn: "Re: Can't compile this code:"
- Reply: Alwyn: "Re: Can't compile this code:"
- Reply: B. v Ingen Schenau: "Re: Can't compile this code:"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 25 Nov 2004 20:07:25 +1100
"Alwyn" <dt015a1979@mac.com.invalid> wrote in message
news:241120041137162728%dt015a1979@mac.com.invalid...
| In article <30j3caF316oodU1@uni-berlin.de>, Val \
| <chrisval@bigpond.com.au> wrote:
| >
| > I don't know if it is just my implementation that is broken,
| > but I have tried a few times to use this function in a safe
| > manner, but it has been a very difficult one for me to trap
| > errors for(specifically for malformed command strings).
|
| I don't know about Windows, but on a POSIX-compliant system, the
| following applies:
|
| <quote>
| If string is a NULL pointer, system() will return non-zero if the
| command interpreter sh(1) is available, and zero if it is not.
|
| The system() function returns the exit status of the shell as returned
| by
| waitpid(2), or -1 if an error occurred when invoking fork(2) or
| waitpid(2). A return value of 127 means the execution of the shell
| failed.
| </quote>
|
| I believe the shell will return 0 even though it may have failed to
| execute the command passed to it.
Hmn, very interesting.
| > From my understanding (apart from the return value of system),
| > 'errno' should also be set to one of the following as well,
| > should an error occur:
| >
| > ENOENT Path or file function not found
| > ENOEXEC Exec format error
| > ENOMEM Not enough memory
| >
| > ...but, errno never yields a result other than zero.
|
| I'm not aware that this is required by any standard.
My bad, you are correct. The standard does not specify
that it must set 'errno', but my compiler documentation
does. FWIW, here is what it says:
Return Value
If command is a NULL pointer, system returns
nonzero if a command processor is available.
If command is not a NULL pointer, system
returns 0 if the command processor was successfully started.
If an error occurred, a -1 is returned and errno is set to
one of the following:
ENOENT Path or file function not found
ENOEXEC Exec format error
ENOMEM Not enough memory
My main frustration was, that even though it is documented
as such, I haven't been able to trap any of these errors
via 'errno', as it is always zero.
| Generally speaking, if the command given to 'system' fails to execute,
| there is no way for your program to know about it. This has led some
| people to advise against the use of this library function.
That is all fair and well I suppose, but it's a mystery
to me why such seemingly simple things, should be such a
PITA.
This function is ultimately therefore just as dangerous
as using 'gets()' :-).
Cheers.
Chris Val
- Next message: Chris \( Val \): "Re: Can't compile this code:"
- Previous message: Chris \( Val \): "Re: Pointers"
- In reply to: Alwyn: "Re: Can't compile this code:"
- Next in thread: Alwyn: "Re: Can't compile this code:"
- Reply: Alwyn: "Re: Can't compile this code:"
- Reply: B. v Ingen Schenau: "Re: Can't compile this code:"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|