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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.