|
发表于 2019-7-16 16:08:18
|
显示全部楼层
posix_spawn 执行命令的示例代码如下:
- pid_t pid;
- char *argv[] = {
- "/bin/ls", //path
- "-al", //parameter1
- "/", //parameter2
- NULL
- };
-
- posix_spawn(&pid, argv[0], NULL, NULL, argv, NULL);
-
- printf("pid=%d,child pid = %d\n",getpid(),pid);
-
- int stat;
- waitpid(pid,&stat,0);
- printf("stat is %d\n",stat);
复制代码
NSTask 执行命令的代码如下:
- NSTask *task = [[NSTask alloc] init];
- task.launchPath = @"/bin/ls";
- task.arguments = [NSArray arrayWithObjects:
- @"-al",
- @"/",
- nil];
- [task launch];
- [task waitUntilExit];
复制代码 |
|