Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kareman/ntbtask
A Cocoa class for running shell commands, supporting asynchronous I/O. Specifically it's a wrapper for NSTask making it simpler to use.
https://github.com/kareman/ntbtask
Last synced: 30 days ago
JSON representation
A Cocoa class for running shell commands, supporting asynchronous I/O. Specifically it's a wrapper for NSTask making it simpler to use.
- Host: GitHub
- URL: https://github.com/kareman/ntbtask
- Owner: kareman
- License: epl-1.0
- Created: 2014-05-01T14:31:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-15T12:33:18.000Z (over 10 years ago)
- Last Synced: 2024-05-09T15:18:23.704Z (6 months ago)
- Language: Objective-C
- Homepage:
- Size: 207 KB
- Stars: 39
- Watchers: 5
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
NTBTask
=======A Cocoa class for running shell commands, supporting asynchronous I/O. Specifically it's a wrapper for NSTask making it simpler to use.
## Installation
Add NTBTask.h and NTBTask.m to your project.
## Usage
#### Get output from command
```Objective-C
NTBTask *task = [[NTBTask alloc] initWithLaunchPath:@"env"];
NSString *output = [task waitForOutputString];
```#### Send input to command
```Objective-C
NTBTask *task = [[NTBTask alloc] initWithLaunchPath:@"cat"];
NSString *input = @"What goes in, must come out";
[task write:input];
NSString *output = [task waitForOutputString];
```
#### Add arguments```Objective-C
task.arguments = @[ @"testing testing", @"123" ];
```#### Run shell script
```Objective-C
NTBTask *task = [[NTBTask alloc] initWithLaunchPath:@"bash"];
NSString *slowscript = @"echo 'sleeping for 0.3'\n"
"sleep 0.3\n"
"echo 'sleeping for 0.3'\n"
"sleep 0.3\n"
"echo 'sleeping for 0.3'\n"
"sleep 0.3";
[task writeAndCloseInput:slowscript];
[task launch];
```#### Get continuous output
```Objective-C
NTBTask *task = [[NTBTask alloc] initWithLaunchPath:@"cp"];
NSString *tempdir = NSTemporaryDirectory();
task.arguments = @[ @"-Rpnv", @".", tempdir ];NSMutableString *result = [[NSMutableString alloc] init];
task.outputHandler = ^(NSString *output)
{
[result appendString:output];
[self newOutputAvailable:output];
};
task.completionHandler = ^(NTBTask *thistask)
{
[self doSomethingWhenCopyingIsFinished];
};[task launch];
```