0

I am trying to execute a command for creating a Cordova Project in my Cocoa Desktop App but It doesn't work.

That's my code:

NSTask *task = [NSTask new];
    [task setLaunchPath:@"/Documents/Cordova/bin/ ./create ~/Documents/Cordova/HelloWorld2 org.apache.cordova.HelloWorld2 HelloWorld2"];
    [task setArguments:[NSArray arrayWithObjects:@"-l", @"-a", @"-t", nil]];

    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput:pipe];

    [task launch];

    NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile];

    [task waitUntilExit];
   // [task release];

    NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog (@"got\n%@", string);

And that's output:

2013-04-02 23:48:18.968 Phonegap-ProjectCreator[2209:303] launch path not accessible
2013-04-02 23:48:18.970 Phonegap-ProjectCreator[2209:303] (
    0   CoreFoundation                      0x00007fff8b2b80a6 __exceptionPreprocess + 198
    1   libobjc.A.dylib                     0x00007fff88d7e3f0 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff8b2b7e7c +[NSException raise:format:] + 204
    3   Foundation                          0x00007fff8bd21cd2 -[NSConcreteTask launchWithDictionary:] + 409
    4   Phonegap-ProjectCreator             0x0000000100002a4a -[MainWindow createProject:] + 314
    5   AppKit                              0x00007fff94506a59 -[NSApplication sendAction:to:from:] + 342
    6   AppKit                              0x00007fff945068b7 -[NSControl sendAction:to:] + 85
    7   AppKit                              0x00007fff945067eb -[NSCell _sendActionFrom:] + 138
    8   AppKit                              0x00007fff94504cd3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 1855
    9   AppKit                              0x00007fff94504521 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 504
    10  AppKit                              0x00007fff94503c9c -[NSControl mouseDown:] + 820
    11  AppKit                              0x00007fff944fb60e -[NSWindow sendEvent:] + 6853
    12  AppKit                              0x00007fff944f7744 -[NSApplication sendEvent:] + 5761
    13  AppKit                              0x00007fff9440d2fa -[NSApplication run] + 636
    14  AppKit                              0x00007fff943b1cb6 NSApplicationMain + 869
    15  Phonegap-ProjectCreator             0x00000001000011d2 main + 34
    16  libdyld.dylib                       0x00007fff89ced7e1 start + 0
    17  ???                                 0x0000000000000003 0x0 + 3
)

I don't understand what is the problem? It can't find path for executing or can't execute?

cmltkt
  • 193
  • 3
  • 16

2 Answers2

3

The launch path is the path to be launched, not the command line to be invoked. It should only contain the path to the executable to be run.

The arguments array is the arguments that should be passed. You are mixing the two.


Your executable looks to be "/Documents/Cordova/bin/create"

Arguments appear to be something like:

 NSArray *args = @["-l", "~/Documents/Cordova/HelloWorld2", "-a", "org.apache.cordova.HelloWorld2", "-t", "HelloWorld2"];

I.e. arguments have values and the values are interleaved with the arguments in the arguments array.

bbum
  • 162,346
  • 23
  • 271
  • 359
1

I found the solution. I am new to objective c and I realized I made a lot of mistake.

That's the solution:

/** Path to Application **/
NSString *path = @"/Users/username/Documents/Cordova/bin/create"; 

/** Arguments **/
NSArray *args = [NSArray arrayWithObjects:@"/Users/username/Documents/Cordova/HelloWorld3",@"org.apache.cordova.HelloWorld3",@"HelloWorld3", nil];
[[NSTask launchedTaskWithLaunchPath:path arguments:args] waitUntilExit];
cmltkt
  • 193
  • 3
  • 16