{"id":775,"date":"2023-04-01T16:56:29","date_gmt":"2023-04-01T16:56:29","guid":{"rendered":"http:\/\/robinluo.top\/?p=775"},"modified":"2023-04-01T18:33:47","modified_gmt":"2023-04-01T18:33:47","slug":"objective-c-%e8%bf%9b%e7%a8%8b%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/robinluo.top\/?p=775","title":{"rendered":"objective-c \u8fdb\u7a0b\u7ba1\u7406"},"content":{"rendered":"\n<p>NSProcessInfo *proc = [NSProcessInfo processInfo];<\/p>\n\n\n\n<p>\u83b7\u53d6\u5f53\u524d\u8fdb\u7a0b\u5bf9\u8c61<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u8fdb\u7a0b\u53c2\u6570<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSProcessInfo *proc = [NSProcessInfo processInfo];<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSArray *args = [proc arguments];<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&#8221;args : %@&#8221; , args);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSDictionary *env = [proc environment];<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&#8221;env : %@&#8221; , env);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; int pid = [proc processIdentifier];<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&#8221;pid : %d&#8221; , pid);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSString *processName = [proc processName];<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&#8221;processName : %@&#8221; , processName);<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSString *hostName = [proc hostName];<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&#8221;hostName : %@&#8221; , hostName);<\/p>\n\n\n\n<p>\u5b50\u8fdb\u7a0b\u7ba1\u7406 \u901a\u8fc7NSTask \u8c03\u7528shell \u542f\u52a8\u5b50\u8fdb\u7a0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        NSTask *task = &#91;NSTask new];\n        \n        task.launchPath = @\"\/bin\/pwd\";\n        task.currentDirectoryPath = NSHomeDirectory();\n        \/\/NSFileHandle *output = task.standardOutput;\n        \/\/NSFileHandle *input = task.standardInput;\n        &#91;task launch];\/\/\u6267\u884c \u4e14\u5b50\u8fdb\u7a0b\u4f1a\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u51fa\u6d41\u5230\u4e3b\u8fdb\u7a0b\n        &#91;task waitUntilExit];\n        NSLog(@\"end\");<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>NSProcessInfo *proc = [NSProcessInfo processInfo]; \u83b7\u53d6\u5f53\u524d\u8fdb\u7a0b\u5bf9\u8c61 \u4ee5\u4e0b\u662f\u4e00\u4e9b\u8fdb\u7a0b\u53c2\u6570 &nbsp; &nbsp; &nbsp; &nbsp; NSProcessInfo *proc = [NSProcessInfo processInfo]; &nbsp; &nbsp; &nbsp; &nbsp; NSArray *args = [proc arguments]; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&#8221;args : %@&#8221; , args); &nbsp; &nbsp; &nbsp; &nbsp; NSDictionary *env = [proc environment]; &nbsp; &nbsp; &nbsp; &nbsp; NSLog(@&#8221;env : %@&#8221; , env); &nbsp; &nbsp; &nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[132],"tags":[],"_links":{"self":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/775"}],"collection":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=775"}],"version-history":[{"count":9,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/775\/revisions"}],"predecessor-version":[{"id":798,"href":"https:\/\/robinluo.top\/index.php?rest_route=\/wp\/v2\/posts\/775\/revisions\/798"}],"wp:attachment":[{"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robinluo.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}