下面是如何在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 ];