header

Torsten Curdt’s weblog

Cannot execvp a Carbon application

Here is a little test program to demonstrate a problem I am facing at the moment. I have an application (that I cannot change) that is calling out to execvp to execute an external program. Now I want to replace this external program by a Carbon application. Unfortunately for some reason the Carbon runtime cannot find the nib file (kIBCarbonRuntimeCantFindNibFile) It only succeeds if the this little test wrapper is inside the bundle and very next to the myapp executable.


#include "stdio.h"
int main(int argc, char** argv) {
  char* exe = "carbon/build/Release/myapp.app/Contents/MacOS/myapp";
  char* args[] = { "", NULL };

  printf("executing [%s]\n", exe);
  execvp (exe, args);
  printf("done\\n");
}

As execvp replaces the original program I just assume the nib will get searched based on the path of the wrapper – not the program that is getting called by execvp. Which I still think is weird, but anyway. If someone has further details, could confirm or explain …maybe even has a smart way around this – please let me know!!

UPDATE:
the above test program has a bug and “unfortunately” works and does not reproduce the error. Now that is even worse :-( …but just for the record it should have been.


#include "stdio.h"
int main(int argc, char** argv) {
  char* exe = "carbon/build/Release/myapp.app/Contents/MacOS/myapp";
  char* args[] = { exe, NULL };

  printf("executing [%s]\n", exe);
  execvp (args[0], args);
  printf("done\\n");
}

Reading the man page in detail sometimes *does* help.

  • James Turner
    It's strange that the NIB file isn't found, I'd normally expect the app to launch, but be unable to take focus - this may be a Carbon / Cocoa thing though. The simplest solution is to invoke the bundle via the 'open' utility, so from the command line, do:

    open path/to/my.app

    instead of

    ./path/to/my.app/Contents/MacOS/myapp

    The former method uses LaunchServices, and is 'the same' as double-clicking the bundle in the Finder. Only issue then is passing command-line options through, see the man page for 'open' for what it can and can't do (basically you can pass a filename or URL to launch).

    The next best solution is some mac-specific C code that calls LaunchServices directly. For more on that approach, best to see the Apple docs:

    http://developer.apple.com/doc...
blog comments powered by Disqus