从 C++ 调用 cURL 命令会返回意外的错误代码,如 1792 和 6656
Calling cURL command from C++ returns unexpected error codes like 1792 and 6656
我有一个在嵌入式Linux上运行的C++应用程序,它构建并调用cURL命令以将文件复制到FTP服务器。
std::string cmd = "curl --connect-timeout 10 --ftp-create-dirs "
+ localPath + filename + " "
+ ftpPath + filename + " "
+ userAuth;
int retVal = system(cmd.c_str());
根据用于生成命令的变量,这将返回意外的错误代码。例如,当我尝试复制不存在的文件时,retVal
是 6656 而不是预期的 26("找不到本地文件"(,当我关闭服务器时,retVal
是 1792 而不是预期的 7("无法连接到服务器"(。
查看值,我很确定这与字节序有关,但我想了解根本原因。该设备具有ARMv7处理器,并使用小端格式。
这与字节序无关,但记录在system
手册页中:
在最后两种情况下,返回值是"等待状态",可以是 使用 waitpid(2( 中描述的宏进行检查。 (即 WIFEXITED((, WEXITSTATUS((,等等(。
和WEXITSTATUS
:
WEXITSTATUS(wstatus( 返回子项的退出状态。
这包括 状态参数的最低有效 8 位,即子项 在调用 exit(3( 或 _exit(2( 中指定或作为参数 用于 main(( 中的返回语句。
应使用此宏 仅当 WIFEXITED 返回 true 时。
如果您只想知道命令是否成功,则应使用:
if (WIFEXITED(retVal)) {
int retCode = WIFEXITSTATUS(retVal);
...
} else if (WIFSIGNALED(retVal) {
int signal = WTERMSIG(retVal);
...
} else {
/* process was stopped by a signal */
}
相关文章:
- 错误处理.将系统错误代码映射到泛型
- 为什么我在使用void函数时得到错误代码C2276
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 逻辑运算符上出现错误代码 a')'
- 'val' Arduino 错误代码之前的预期'('
- 我在贪吃蛇游戏中收到了错误代码 -1073741571
- 根据 GetLastError 直接写入磁盘会导致错误代码 5
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- 创建进程 API 失败,在窗口 122 上出现错误代码 10
- 使用另一个函数调用一个函数(都在类中)时出现问题.没有错误代码C++
- 当命令失败时,gzip 会在 C++ 中返回错误代码吗?
- 从 C++ 调用 cURL 命令会返回意外的错误代码,如 1792 和 6656
- WSALookupServiceBegin() 上的错误代码 10022(无效的 arugment)
- C++ Schannel POST 400 错误代码错误请求
- openCL-创建子缓冲区返回错误代码13
- 更新了Runge-Kutta(RK4)C++错误代码中的二阶DE
- 获取有关使用未初始化内存的错误代码
- 排序程序的意外错误代码
- 正在将DJI错误代码记录到流中
- 来自API的错误代码..处理什么是好的做法