Relatively new here so please excuse the dumb question.
I'm currently working with a specific set of commercial DSLR-type cameras (Phase One), and have an SDK provided by the manufacturer. However, there are two components to the SDK - one is dedicated to image capture, written as an Objective C framework, and the other is dedicated to image processing, written as a list of shell commands.
I'd like to build a program with a user interface that will allow me to lay out sequences for both capturing and processing.
Running the camera with the Objective C Framework is relatively straightforward, I've just built a Cocoa app with interface builder. But what is the best way to integrate it with the processing engine, which I can only seem to run from a shell?
So far I've used NSTask to call some bash scripts I've written separately, and that's worked fine...but now I need to save some command line output which I get back from my shell scripts after they've processed the files to as variables in the overall app.
Everywhere I've read says that there's no elegant way to do this, and that the ways to work around it (writing to a file, having the main program read from that file, etc.) are big security risks.
So I'm thinking that there has to be a better way to integrate these two halves of the SDK. Or is my approach alright, and there's a safe way to pull terminal output into my program? Thanks in advance.
You can read STDOUT from the NSTask. Here is an example to get you started:
NSPipe *readPipe=NSPipe.pipe;
readPipe.fileHandleForReading.readabilityHandler=^(NSFileHandle *fh){
NSData *data=fh.availableData;
if(!data)
{
NSLog(@"Script STDOUT closed!");
fh.readabilityHandler=NULL;
return;
}
// process the data here
NSString *s=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
// NOTE: there is no guarantee what kind of chunk size your data
// comes in! You may need to concatenate strings until it is complete
};
NSTask *task=NSTask.new;
// set up your task as normal
task.standardOutput=readPipe;
[task launch];