Edit: [Solved] see below.
I'm launching PHP as an NSTask
and trying to pass some command line options to it:
NSTask *php = [[NSTask alloc] init];
[php setLaunchPath: phpPath];
NSArray *args = [[NSArray alloc] initWithObjects: @"-r 'echo 123;'", nil ];
[php setArguments: args];
[php launch];
When I run this from Objective-C I always get the following PHP errors:
For:
@"-r 'echo 123;'"
@"-r \'echo 123;\'"
@"-r \"echo 123;\""Parse error: syntax error, unexpected $end in Command line code on line 1
For:
@"-r 'echo \'hello\';'"
Parse error: syntax error, unexpected T_STRING in Command line code on line 1
For:
@"--run 'echo 123;'"Usage: php [options] ...
It should be noted that all errors are reported from the PHP interpreter when called from Objective-C, but when I try the exact same option string on the command line, it works as expected.
What's wrong here? how should I write arguments to be correctly passed to the NSTask?
PS: My real goal is to execute some include()
lines instead of the echo, which doesn't work either, and instead I get an error of an unexpected Encapsed String.