2012-03-03 70 views
0

我从我的应用程序运行zip实用程序来创建存档。类似的代码如下:如何使用NSTask和输入数据运行unix实用程序?

NSString *toolPath = @"/usr/bin/zip"; 
NSTask *task = [[[NSTask alloc] init] autorelease]; 
[task setLaunchPath:toolPath]; 
[task setArguments:arguments]; 
[task launch]; 

,其中争论通常是要字符串的文件的路径。但是,当需要创建受密码保护的归档文件(带-e参数)时,密码会在启动后输入两次。在终端它看起来像这样:

$ zip -e archive.zip file_to_archive.txt 
Enter password: 
Verify password: 

我该如何在应用程序中输入密码?

回答

0

根据man zip

-P password 
    --password password 
      Use password to encrypt zipfile entries (if any). THIS IS INSE- 
      CURE! Many multi-user operating systems provide ways for any 
      user to see the current command line of any other user; even on 
      stand-alone systems there is always the threat of over-the- 
      shoulder peeking. Storing the plaintext password as part of a 
      command line in an automated script is even worse. Whenever 
      possible, use the non-echoing, interactive prompt to enter pass- 
      words. (And where security is truly important, use strong 
      encryption such as Pretty Good Privacy instead of the relatively 
      weak standard encryption provided by zipfile utilities.) 

可以使用-P参数解决这个问题,我觉得你并不需要这么多的安全性。

+0

非常感谢! – ifau 2012-03-03 16:37:58

相关问题