C++中system函数返回-1的问题
我们的工程中在Linux64位平台上有一个地方调用外部的一个名为step的程序,该程序为32位,在C++语言中用system函数来调用:
error_flag = system(my_command);
结果运行的时候外面的那个程序也启动起来了,在命令行窗口中看到运算过程,写出的文件也没有问题,结果也是正确的,但是最后error_flag返回值就是为-1,
我想查看一下errno,就加了这么两句:
printf("errno = %d\n", errno);
结果打印出来的errno居然是0!没有错误,可system的返回值就是-1。
我于是另外写了一个小程序;
------------------------------------------
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main()
{
char com[1024];
int ret;
sprintf( com, "/home/eta/step/step32 uppad_step 2000000 0" );
ret = system( com );
printf( " ret = %d\n", ret );
}
--------------------------------------------------
还是编译出64位程序去调用那个32位的程序step,一切都很正常,ret也等于0.
我就是很奇怪为什么在我们的工程中调用step就是返回-1,返回-1也就算了,为什么errno居然还是0?
太奇怪了