Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 956 Bytes

README.md

File metadata and controls

29 lines (25 loc) · 956 Bytes

ZRTasking

Simple NSTask wrapper to run shell command synchronously or asynchronously

Usage

Run command synchronously

  int status;
  NSData* result = runCommandSync(@"/usr/bin/curl -fsSL taobao.com", YES, &status);
  NSLog(@"data length: %ld, status: %d", [result length], status);

Run command asynchronously

  runCommandAsync(@"/usr/bin/curl -fsSL taobao.com", YES, ^(NSData * _Nonnull data, int exitStatus) {
      NSLog(@"data length: %ld, status: %d", [data length], exitStatus);
  });

Run command asynchronously with timeout

  runCommandAsyncTimeout(@"echo begin;sleep 10;echo end", YES, 2, ^(NSData * _Nonnull data, int exitStatus) {
                if (exitStatus == CMD_TIMEOUT_ERR) {
                    NSLog(@"command running timeout: %@", data);
                } else {
                    NSLog(@"command complete: %@", data);
                }
            });