这里我在linux下的代码中使用。 在系统函数中使用cp命令。什么系统函数和cp命令在C/Linux中返回
我知道系统函数它会返回0 if命令成功执行,否则它会返回错误代码。
如果这里我用正确的源和目标路径比我得到的输出喜欢这个
Number == 0
如果我给错了源和目标路径比我得到
cp: cannot create regular file `/home/sam/test/test': No such file or directory
Number == 256
cp: cannot stat `/home/sam/main/test2/test': Not a directory
Number == 256
在这里,我想知道错误代码cp
命令什么cp命令在这里返回。
我的问题是这里
1 System function return error code of cp command?
2 Can i get error code of cp command from source code of cp command?
3 i want to handle all types of error in this cp command.
代码:
#include <stdlib.h>
#include <stdio.h>
void main()
{
int a;
a = system("cp /home/sam/main/test /home/sam");
printf("Number == %d\n",a);
}
所以,任何机构,请给我解释一下这一切
请停止使用无效的主要()。 main()函数应该返回int。 (如果cp或sh的创建者会使用'void main()',会发生什么?) – wildplasser 2012-03-21 11:19:30
为什么不使用mmap()或open()/ read()/ write()来复制文件而不是使用系统()执行cp命令? – dAm2K 2012-03-21 13:10:17