美文网首页
Mac下获取当前程序路径

Mac下获取当前程序路径

作者: c57090b7a7fe | 来源:发表于2016-07-21 13:56 被阅读635次

    1

    NSString* getExePath()
    { 
        char buf[0] = {0}; 
        uint32_t size = 0;          
        _NSGetExecutablePath(buf,&size); 
        char* path = (char*)malloc(size+1); 
        path[size] = 0; 
        _NSGetExecutablePath(path,&size); 
        char* pCur = strrchr(path, '/'); 
        *pCur = 0; 
        NSString* nsPath = [NSString stringWithUTF8String:path];
        free(path);
        path = NULL;
        return nsPath;
    }
    

    执行命令脚本

    void runSystemCommand(NSString *cmd)
    {
        [[NSTask launchedTaskWithLaunchPath:@"/bin/sh"
                                  arguments:@[@"-c", cmd]]
         waitUntilExit];
    }
    runSystemCommand(@"python /Users/1.py");
    

    相关文章

      网友评论

          本文标题:Mac下获取当前程序路径

          本文链接:https://www.haomeiwen.com/subject/exybjttx.html