如何在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];
下面是如何在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];
相关文章推荐
- 如何在iPhone程序中调用外部命令
- oracle如何使用java source调用外部程序
- 如何在java程序中调用linux命令或者shell脚本
- 用Ant调用系统命令或外部程序
- 从Ant调用系统命令或外部程序
- [转载]C#如何实现对外部程序的动态调用
- 如何检查外部调用程序的状态
- 在java程序中如何调用linux的命令?如何调用shell脚本呢?
- MySQL 实现调用外部程序和系统命令
- 如何在java程序中调用linux命令或者shell脚本
- 如何在java程序中调用linux命令或者shell脚本
- C#如何调用外部exe程序 (转)
- 如何在java程序中调用linux命令或者shell脚本
- 如何在java程序中调用linux命令或者shell脚本
- [MySQL FAQ]系列 -- mysql如何调用系统外部程序
- CIV 如何在自己的程序中调用外部程序
- java如何调用外部程序
- C#中利用process类调用外部程序以及执行dos命令
- Linux下的C程序如何调用系统命令,并获取系统的输出信息到C程序中
- linux下如何在程序中调用shell命令