The manual page "man system" contains the following section:
- If command is NULL, then a nonzero value if a shell is available, or 0 if no shell is available.
which basically indicates that I can check with
if(system(NULL) != 0) {foo;}
if a shell is currently available or not.
When do I have to consider to do so? Because I never ever got an error which was related to this specific case.
Also from man system
:
[...] even though POSIX.1-2001 requires a conforming implementation to provide a shell, that shell may not be available or executable if the calling program has previously called chroot(2) [...]
So that's a possible case where /bin/sh
might not be available. In practice I wouldn't worry too much about it. (But then again, I probably wouldn't use system
in real code in the first place.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With