Как запустить утилиту unix с помощью NSTask и ввода данных? - PullRequest
0 голосов
/ 03 марта 2012

Я запускаю утилиту zip из моего приложения для создания архива. Код похож на следующий:

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:

Как мне сделать, чтобы ввести пароль в приложении?

1 Ответ

0 голосов
/ 03 марта 2012

Согласно 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, я думаю, вам не нужно много безопасности.

...