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];

        }

扫描二维码关注公众号,回复: 520997 查看本文章

        

        pclose(pipe);

        return output;

    }

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

猜你喜欢

转载自siruoxian.iteye.com/blog/2168640