2 chenlong12580 chenlong12580 于 2014.10.14 00:45 提问

system function can not run correct after modify the enviroment?

#include
#include
#include
#include

int main()
{
char *ptr = NULL;
char path[1024] = {0};
char pathori[1024] = {0};
int ret = 0;

ptr = getenv("PATH");

strcpy(pathori, ptr);

printf("pathori=%s\n", pathori);

setenv("PATH", "/home/chenlong12580/develop/bina", 1);

ret = system("test");
printf("ret=%d\n", ret);

ptr = getenv("PATH");
memset(path, 0, 1024);
strcpy(path, ptr);
printf("path1=%s\n", path);

setenv("PATH", pathori, 1);
ptr = getenv("PATH");
memset(path, 0, 1024);
strcpy(path, ptr);
printf("path2=%s\n", path);

return 0;

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!