C++: system(0) Returns 0

后端 未结 2 669
庸人自扰
庸人自扰 2020-12-20 03:52

When I call system(0) it returns 0, which means shell is not available.

When a command using system (calls gcc to compile a hello world pr

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 04:38

    Man says:

    The value returned is -1 on error (e.g. fork(2) failed), and the return status of the command otherwise. This latter return status is in the format specified in wait(2). Thus, the exit code of the command will be WEXITSTATUS(status). In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127). If the value of command is NULL, system() returns nonzero if the shell is available, and zero if not.

    If you have no sh in your path or is not an executable is not available. Check your configuration.

    If system returns -1 may be a problem executing fork, so check errno variable value or maybe the return status of the invoked command, that may be also -1. Verify exit status of your command executed from chell.

提交回复
热议问题