我正在构建一个简单的GUI,以便在Cocoa中运行亚行命令。我已经找到了几篇不同的文章,说明如何使用NSTask运行shell命令,但并不是专门针对亚行的,而且我很难理解。
我可以运行简单的ADB命令。
adb devicesadb reboot函数
NSString *adbPath = @"~/Android/sdk/platform-tools/adb";
NSString* runADBCommand(NSString *cmd)
{
NSTask *adbDevices = [[NSTask alloc] init];
[adbDevices setLaunchPath:adbPath];
adbDevices.arguments = @[cmd];
NSPipe *pipe;
pipe = [NSPipe pipe];
[adbDevices setStandardOutput:pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[adbDevices launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *adbComOutput;
adbComOutput = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return adbComOutput;
}调用
- (void)refreshDevices:(id)sender
{
adbOutput.stringValue = runADBCommand(@"devices");
}上面的内容很好,但是当我传递一个更复杂的论点时:
- (void) getVersion:(id)sender
{
runADBCommand(@"shell cat /system/build.prop | grep incremental");
}我只是得到控制台输出,就好像我刚在终端中输入了adb一样。如何将NSTask的命令和参数打包以运行亚行命令?
发布于 2015-01-28 01:57:03
您应该使用-setArguments:方法设置参数,就像下面的示例NSTask shell
https://stackoverflow.com/questions/28182784
复制相似问题