Skip to content

Simple NSTask wrapper to run shell command synchronously or asynchronously

License

Notifications You must be signed in to change notification settings

zhaorui/ZRTasking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
                }
            });

About

Simple NSTask wrapper to run shell command synchronously or asynchronously

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published