前言
- 本文以执行shell 为例子,从
#include <spawn.h>
的popen方法为线索FILE *popen(const char *, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(popen)) __swift_unavailable_on("Use posix_spawn APIs or NSTask instead.", "Process spawning is unavailable.");
- code
I、popen
- popen
// popen(@"killall -9 WeChat", @"r");//#include <stdio.h>
II、 NSTask
- /Users/devzkn/code/github/gnustep-base/Source/NSTask.m
/Users/devzkn/code/github/gnustep-base/Headers/Foundation/NSTask.h
launchedTaskWithLaunchPath: arguments:
&kndoShellCmd:
III、posix_spawn
3.1 posix_spawn
status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, (char **)&myenviron);
- ` posix_spawnp(&pid, path, &fact, &attr, args, environ);`
// 方式一 run("killall -9 WeChat");// //方式二 NSArray* args = @[@"-9",@"WeChat"]; [KNnoZombieRunobjc Run:@"killall" withParams:args];//#include <spawn.h>
See Also
/Users/devzkn/bin/knpost NSTask_posix_spawn_popen NSTask、posix_spawn、popen 的应用例子 -t objc #原来""的参数,需要自己加上""
转载请注明:张坤楠的博客 > NSTask_posix_spawn_popen