Domanda

I'm trying to build an app for the iPhone (or iPad, for that matter) in which I want to run some shell commands. The iPhone on which I want it to work is not jailbroken.

The system() command seems to work in executing a shell command, but output and input is of course still a problem. I learned that NSTask may be used for these kinds of things and that it's present, though not documented. (Including the Mac NSTask.h seems to work perfectly)

Now the problem is that when executing this code:

NSTask *task;
task=[[NSTask alloc] init];
task.launchPath=@"/usr/bin/ls";
task.arguments=[NSArray array];
NSPipe *pipe=[NSPipe pipe];
task.standardOutput=pipe;
task.standardError=pipe;
NSFileHandle *output=pipe.fileHandleForReading;
pipe=[NSPipe pipe];
task.standardInput=pipe;
[task launch];

where pipe is for future I/O, it generates an error reading:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'launch path not accessible'

I already tried quite a few possible paths for the unix bin directory but either I can't find it or my app doesn't have permissions to list files. -.-

How do I execute shell commands on an iPhone while having control over both input and output of that command?

È stato utile?

Soluzione

Any attempts to directly create a secondary process in iOS will be denied by the security policy unless you are running on a jailbroken phone.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top