NSTask Class on OS X API , lets you run another program as a subprocess and monitor that program’s execution
Questions tagged [nstask]
459 questions
3
votes
1 answer
Keep a NSTask Session Running - Cocoa
I run a simple grep command in my Cocoa app like so:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/grep"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"foo", @"bar.txt", nil];
[task setArguments:…

lab12
- 6,400
- 21
- 68
- 106
3
votes
3 answers
AuthorizationExecuteWithPrivileges() as root Error
I am a beginner in cocoa...
I just want to start Apache and other process in my Cocoa App.
Here is my code :
OSStatus myStatus;
AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
AuthorizationRef myAuthorizationRef;
FILE *pipe…

Le roukin
- 95
- 1
- 10
3
votes
2 answers
NSTask Race Condition With ReadabilityHandler Block
Basic Setup
I use NSTask to run a process that optimizes images. This process writes output data to stdout. I use the readabilityHandler property of NSTask to capture that data. Here is the abbreviated setup:
NSTask *task = [[NSTask alloc]…

Bryan
- 4,628
- 3
- 36
- 62
3
votes
2 answers
Accessing Bundle of main application while running XCTests
In tests target -> General -> Testing: set Host Application to None, so that no app gets launched.
But in that case I cannot use Bundle.main.resourcePath and access resources of my main application (in which some command files are included as…

Annie Dev
- 282
- 1
- 10
3
votes
3 answers
Catch credential needed with NSTask and rsync
Fist post for a french developer!
I'm trying to create a simple synchronization using rsync and objective-c.
So I used NSTask like that :
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/rsync"];
NSArray* args = [NSArray…

Mickael
- 271
- 1
- 3
- 8
3
votes
1 answer
How to wait NSTask to finish in async block
NSURLSessionDataTask *dataTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error)
{
NSLog(@"Did fail with error %@" , [error…

jimwan
- 1,086
- 2
- 24
- 39
3
votes
1 answer
Can't execute shell script commands in sandboxed cocoa app
I developed a cocoa application that builds, archives and creates iOS application files. Now I want to release it to Mac App Store. My app runs correctly, but not in sandbox mode. App structure is as following:
MyApp.app
|_Contents
|_Resources
…

Murat Adıgüzel
- 138
- 8
3
votes
1 answer
NSTask environment variables in swift
How can I set an environment variable for my application in swift? Using the editor schema It works only while running with xcode but not in the compiled application of course.
I already tryed to do:
let environment: NSDictionary = ["launched" :…

FakeAccount
- 242
- 1
- 3
- 19
3
votes
1 answer
com.apple.xpc.launchd.oneshot
In an XCTestCase test, I created a NSTask object and set it to run printenv. Then after the NSTask finished, I ran printenv using fork and execv. The output from both was identical except for one environment variable.
NSTask:…

fumoboy007
- 5,345
- 4
- 32
- 49
3
votes
2 answers
NSTask executed only once
I'm having trouble executing different NSTask's. Same launchPath, different arguments. I have a class who's instances administer own NSTask objects and depending on arguments those instances were initialized with - dependent NSTask object is being…

Eimantas
- 48,927
- 17
- 132
- 168
3
votes
1 answer
Sending control+c (SIGINT) to NSPIPE in objective-C
I am trying to terminate an openvpn task, spawned via NSTask.
My question:
Should I send ctrl+c (SIGINT) to the input NSPipe for my NSTask?
inputPipe = [NSPipe pipe];
taskInput = [inputPipe fileHandleForWriting];
NSString dataString =…

Ron
- 1,610
- 15
- 23
3
votes
1 answer
Swift and NSTask hangs
i am new to the Mac World. I'm using Swift and i am trying to run external processes one at a time.
Now everything works fine, as long, as it is debugged, by which I mean: Run in Xcode with Debugger attached.
I do not change anything and try to…

Andreas
- 828
- 4
- 15
3
votes
1 answer
Multiple Authorization In Cocoa App
I'm writing a cocoa app which needs to modify system proxy settings ( I'm using networksetup to do that ).The problem is that it needs system administrator level access to change proxy settings. I tried running both running an NSTask as…

Sepehrom
- 1,335
- 2
- 16
- 33
3
votes
0 answers
Start multiple NSTask with root privilege asking for password only once
I would like to start a lot of NSTasks that require root privilege, I found that I should use Apple's Authorization Kit and I found STPrivilegedTask, which is designed for that.
The thing is, when I start a STPrivilegedTask, it will ask me for the…

Ashbay
- 1,641
- 13
- 20
3
votes
0 answers
App crash when use nstask with sandbox
I used this code in my app:
//create task
NSTask * task=[[NSTask alloc] init];
[task setLaunchPath:@"/bin/ps"];
NSArray * arguments = [NSArray arrayWithObjects: @"axco command,pcpu",nil];
[task setArguments:arguments];
NSPipe *pipe = [NSPipe…

ThuanNguyen
- 31
- 2