我试图把NSString放在一个修改过的路径上,因为我不能使用路径" / subfolder" 我的代码是:
NSString *bath =[NSString stringWithFormat:@"%@/path", path];
pid_t pid;
int status;
const char *argv[] = {"mkdir", bath, NULL};
posix_spawn(&pid, "/bin/mkdir", NULL, NULL, (char* const*)argv, NULL);
waitpid(pid, &status, WEXITED);`
答案 0 :(得分:0)
NSStrings需要先转换为C字符串,然后才能将它们包含在argv
数组中。
这样做:
NSString *bath =[NSString stringWithFormat:@"%@/path", path];
const char *cBath = [bath UTF8String];
if (cBath == NULL)
{
print("cBath is null ; why is path also null?");
return;
}
pid_t pid;
int status;
const char *argv[] = {"mkdir", cBath, NULL};
posix_spawn(&pid, "/bin/mkdir", NULL, NULL, (char* const*)argv, NULL);
waitpid(pid, &status, WEXITED);`