objective c - Launching App using 'launchedTaskWithLaunchPath' Cocoa/objecive-c API -
i need launch 'textmate' app, , used following code.
[nstask launchedtaskwithlaunchpath:@"/applications/textmate.app" arguments:[nsarray arraywithobjects:@"hello.txt", nil]];
but, got following error return.
*** nstask: task create path '/applications/textmate.app' failed: 22, "invalid argument". terminating temporary process.
- what's wrong code? tried run "textmate hello.txt".
added
i make run follows.
[nstask launchedtaskwithlaunchpath:@"/applications/textmate.app/contents/macos/textmate" arguments:[nsarray arraywithobjects:@"hello.txt", nil]];
and asked another question see how many other ways available.
in case, invalid parameter application's name.
if check documentation nstask you'll see method you're using wrapper low-level exec() system call. means need provide name of actual executable or binary file able create process. in case, you're giving directory (use terminal confirm app bundles in /applications directories). that's why barfs.
you inside textmate's bundle directory find actual executable (should somewhere in /applications/textmate.app/contents/macos). modify code call actual executable.
however, seem correct, cocoa-ish way using nsworkspace, might openfile:withapplication: method, seems need, , in case specify application bundle directory parameter, way doing it.
official documentation here.
by way, can't take credit it; see this stackoverflow answer learn more topic.
Comments
Post a Comment