NSTask 问题 [英] NSTask Question

查看:70
本文介绍了NSTask 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的 NSTask 为我解压缩文件.如果路径没有空格,这可以正常工作,但是当它出现时,它找不到任何文件.我无法对 " 符号进行硬编码,因为我将 zip 文件存储在系统分配的临时文件夹中.

I'm trying to get my NSTask to unzip a file for me. This works fine if the path has no spaces, but when it does, it can't find any of the files. I can't hardcode the " signs because I'm storing the zip file in a temporary folder, which is assigned by the system.

有人知道如何实现吗?

这是我的代码:

NSTask*task = [[NSTask alloc] init];

[task setLaunchPath:@"/usr/bin/unzip"];

NSArray*arguments = [NSArray arrayWithObjects:zipPath,@"-d",path,nil];

[task setArguments:arguments];

[task launch];

[task release];

推荐答案

在参数中有空格看起来不像您的问题 - 请注意,控制台显示的路径名带有空格.带有空格的参数作为单个参数传递,我刚刚确认它会很高兴地解压缩@"a space.zip".您是否检查过该文件确实存在于您认为存在的位置并且您有权访问它?

Having a space in the argument does not look like your problem - note that the console is showing the pathname with a space. An argument with a space is passed as a single argument, I've just confirmed it will happily unzip @"a space.zip". Have you checked the file does exist where you think it does and you have access to it?

这篇关于NSTask 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆