简体   繁体   中英

How to run unix utility with NSTask and input data?

I run zip utility from my app to create archive. Code similar to the following:

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

, where arguments it is typically string with paths to files. However, when need to create a password protected archive (with the -e argument), password is entered after the launch, and two times. In terminal it looks like this:

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

How do I make enter a password in the app?

According to 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.)

You can resolve the problem by using the -P parameter, I think you don't need so much security.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM