gpt4 book ai didi

c - 执行返回 255

转载 作者:行者123 更新时间:2023-12-02 05:45:00 25 4
gpt4 key购买 nike

我的代码在 Mac 上运行,我从 exec 得到 255 返回码。
以下是代码:

    ret = execvp(pArgs[0], pArgs);  

if (ret < 0)
{
ret = errno;
exit(ret);
return false;
}
else if (processId < 0)
{
// fork() failed
return false;
}
else if(Wait)
{
// forked successfuly so wait for exit
if(waitpid(processId, &childstatus, 0) == processId)
{
// codesign command terminted, get return code
if(WIFEXITED(childstatus))
{
if(pCmdRetStatus != NULL)
*pCmdRetStatus = WEXITSTATUS(childstatus);
}

}
}

关于为什么是 255 的任何想法?本质上是一个 hdiutil 调用,很多时候,我得到 255。

最佳答案

UNIX (and therefore Mac OS X) exit statuses被强制进入范围 0-255 无符号。

所以返回值是 -1从您调用 execvp在您的 C 代码中将被处理为 -1,但由于 the rules of the exit() function specification 在操作系统级别将变为 255 .考虑以下示例:

bash> bash
bash2> exit -1
bash> echo $? # The exit status of the last command (bash2)
255

关于c - 执行返回 255,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6459023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com