您的位置:首页 > 其它

如何在iPhone程序中调用外部命令

2009-06-22 14:11 399 查看
下面是如何在iPhone非官方SDK程序中调用外部命令的方法。 - ( NSString * ) executeCommand : ( NSString * ) cmd { NSString * output = [ NSString string ] ; FILE * pipe = popen ( [ cmd cStringUsingEncoding : NSASCIIStringEnc
  

下面是如何在iPhone非官方SDK程序中调用外部命令的方法。

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

}

NSString *yourcmd = [NSString stringWithFormat: @"your command"];

[self executeCommand: yourcmd];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: