从Mac执行脚本

时间:2011-08-09 12:49:33

标签: iphone macos

我是mac开发的新手。我必须通过命令进行iPhone备份。有一个网站解释这个(http://keepmurmuring.blogspot.com/2009/06/iphone-backup-informationnote.html)。我试图用参数执行脚本“System / Library / PrivateFrameworks / MobileDevice.framework / Resources / AppleMobileDeviceHelper.app / Contents / Resources / AppleMobileBackup”。但我无法访问此路径并收到错误“启动路径无法访问”。任何人都可以帮助我访问路径并完成我的任务。

NSString *_filename =@"System/Library/PrivateFrameworks/MobileDevice.framework/Resources/AppleMobileDeviceHelper.app/Contents/Resources/AppleMobileBackup";
    NSArray *arguments = [NSArray arrayWithObjects: @"./ambackup", 
                          @"--backup", @"--target", @"BE1F74EEB98E14D426665D54105DE27821A6C0FE", nil];
    NSTask *task = [[NSTask alloc] init];
    NSPipe *pipe = [NSPipe pipe];
    NSFileHandle *readHandle = [pipe fileHandleForReading];
    NSData *temp = nil;


   NSMutableData *_data = [[NSMutableData alloc] init];

    [task setLaunchPath:_filename];
    [task setArguments:arguments];
    [task setStandardOutput:pipe];
    [task launch];

    while ((temp = [readHandle availableData]) && [temp length]) 
    {
        [_data appendData:temp];
    }


    [task release];

1 个答案:

答案 0 :(得分:1)

您缺少文件名路径中的前导斜杠

NSString *_filename = @"System/Library/PrivateFrameworks/MobileDevice.framework/Resources/AppleMobileDeviceHelper.app/Contents/Resources/AppleMobileBackup";

应该是:

NSString *_filename = @"/System/Library/PrivateFrameworks/MobileDevice.framework/Resources/AppleMobileDeviceHelper.app/Contents/Resources/AppleMobileBackup";