As described in NSTask
's documentation for the setArguments:
method, there should be no need to do special quoting:
Discussion
The
NSTask
object converts both path and the strings in arguments to appropriate C-style strings (using fileSystemRepresentation) before passing them to the task viaargv[]
. The strings in arguments do not undergo shell expansion, so you do not need to do special quoting, and shell variables, such as$PWD
, are not resolved.
If you feel it is necessary, can you please provide some examples of the commands you want to run in the NSTask
?
[UPDATE]: I see in the comments that you indeed are using the NSTask
to execute a bash
shell with -c
, which I had wondered about. I've generally used NSTask
to execute the command directly rather than going through the shell, like this:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/ls"];
[task setArguments:[NSArray arrayWithObjects:@"-l", self.url.path, nil]];
Can you give a more accurate example of the actual command you want to run? For example, are you piping a series of commands together? Perhaps there might be an alternate way to achieve the same results without the need for using the bash
shell...