问题描述
- system function can not run correct after modify the enviroment?
-
#include
#include
#include
#includeint main()
{
char *ptr = NULL;
char path[1024] = {0};
char pathori[1024] = {0};
int ret = 0;ptr = getenv("PATH"); strcpy(pathori, ptr); printf("pathori=%sn", pathori); setenv("PATH", "/home/chenlong12580/develop/bina", 1); ret = system("test"); printf("ret=%dn", ret); ptr = getenv("PATH"); memset(path, 0, 1024); strcpy(path, ptr); printf("path1=%sn", path); setenv("PATH", pathori, 1); ptr = getenv("PATH"); memset(path, 0, 1024); strcpy(path, ptr); printf("path2=%sn", path); return 0;
}
时间: 2024-11-17 19:19:32