system()调用失误提示 Cannot allocate memory
system()调用出错提示 Cannot allocate memory
INT DISK_CreateDir(CHAR * FilePath) //创建文件夹
{
DIR *dirp = NULL;
CHAR Command[COMMAND_LEN] = {0};
if(NULL==FilePath){
NVR_DEBUG("create %s fail",FilePath);
return FALSE;
}
if(NULL==(dirp=opendir(FilePath))){
sprintf(Command,"mkdir -p %s",FilePath);
if(0!=system(Command)){
NVR_DEBUG(" %s fail,errno=%d",Command,errno);
perror("mkdir fail:");
return FALSE;
}else{
NVR_DEBUG(" %s ok",Command);
if(dirp) closedir(dirp);
dirp = NULL;
return TRUE;
}
}else{
NVR_DEBUG("file Exist");
if(dirp) closedir(dirp);
return TRUE;
}
}
程序执行时提示出错:
mkdir fail:: Cannot allocate memory
------解决方案--------------------
C:\>mkdir /?
Creates a directory.
MKDIR [drive:]path
MD [drive:]path
If Command Extensions are enabled MKDIR changes as follows:
MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:
mkdir \a\b\c\d
is the same as:
mkdir \a
chdir \a
mkdir b
chdir b
mkdir c
chdir c
mkdir d
which is what you would have to type if extensions were disabled.
------解决方案--------------------
调一下栈大小试试,用ulimit。
system()的实现 ≈ fork + exec
fork的特点大家都知道,当程序占内存很大时,fork一次也是不小的开销。
有一种可行的做法是另开一个小程序来处理系统命令,主应用程序通过进程间通信的方式发送命令给小程序,小程序再来执行。
------解决方案--------------------
写个临时bat文件,调用这个临时bat文件再试试?
INT DISK_CreateDir(CHAR * FilePath) //创建文件夹
{
DIR *dirp = NULL;
CHAR Command[COMMAND_LEN] = {0};
if(NULL==FilePath){
NVR_DEBUG("create %s fail",FilePath);
return FALSE;
}
if(NULL==(dirp=opendir(FilePath))){
sprintf(Command,"mkdir -p %s",FilePath);
if(0!=system(Command)){
NVR_DEBUG(" %s fail,errno=%d",Command,errno);
perror("mkdir fail:");
return FALSE;
}else{
NVR_DEBUG(" %s ok",Command);
if(dirp) closedir(dirp);
dirp = NULL;
return TRUE;
}
}else{
NVR_DEBUG("file Exist");
if(dirp) closedir(dirp);
return TRUE;
}
}
程序执行时提示出错:
mkdir fail:: Cannot allocate memory
------解决方案--------------------
C:\>mkdir /?
Creates a directory.
MKDIR [drive:]path
MD [drive:]path
If Command Extensions are enabled MKDIR changes as follows:
MKDIR creates any intermediate directories in the path, if needed.
For example, assume \a does not exist then:
mkdir \a\b\c\d
is the same as:
mkdir \a
chdir \a
mkdir b
chdir b
mkdir c
chdir c
mkdir d
which is what you would have to type if extensions were disabled.
------解决方案--------------------
调一下栈大小试试,用ulimit。
system()的实现 ≈ fork + exec
fork的特点大家都知道,当程序占内存很大时,fork一次也是不小的开销。
有一种可行的做法是另开一个小程序来处理系统命令,主应用程序通过进程间通信的方式发送命令给小程序,小程序再来执行。
------解决方案--------------------
写个临时bat文件,调用这个临时bat文件再试试?