`
siruoxian
  • 浏览: 231124 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

oc调用CMD命令

阅读更多

    - (NSString *)executeCommand: (NSString *)cmd

    {

        NSString *output = [NSString string];

        FILE *pipe = popen([cmd cStringUsingEncoding: NSASCIIStringEncoding], "r+");

        if (!pipe)

        return @"";

        

        char buf[1024];

        while(fgets(buf, 1024, pipe)) {

            output = [output stringByAppendingFormat: @"%s", buf];

        }

        

        pclose(pipe);

        return output;

 

    }

  NSLog(@"cmdResult:%@", [selfexecuteCommand: @"ping -c 3 siruoxian.iteye.com"]);

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics