Professional Web Applications Themes

Need advice to launch an application from C tool ? - Mac Programming

To launch an application from my C tool I call fork() and execl(path_str, path_str, NULL) where path_str is the path to a shell script like "open -a /theApplication " Is there a more direct way to do it ?...

  1. #1

    Default Need advice to launch an application from C tool ?

    To launch an application from my C tool I call
    fork() and execl(path_str, path_str, NULL) where
    path_str is the path to a shell script like "open -a /theApplication "

    Is there a more direct way to do it ?
    Alain Guest

  2. #2

    Default Re: Need advice to launch an application from C tool ?

    Hi Alain,


    ca (Alain Birtz) writes: 

    ??

    "open -a /theApplication" *is* a shell script, it's not a path to one.
    If you actually want to execute a shell script like that, use the
    system() function:

    const char script[] = "open -a /theApplication";
    system(script);

    As with all shell scripting, be carefull to quote the parameters
    correctly, like e.g.:

    const char script[] = "open -a '/the Application'";
    system(script);

    If you just want to execute one command line like in this example you
    can use fork()/exec() to avoid the need for quoting, somewhat like
    this:

    const char the_application[] = "/the Application";

    if( 0 == fork() ) {
    execl("/usr/bin/open", "-a", the_application, NULL);
    perror("exec"); /* We only get here in case of error. */
    exit(-1); /* Exit the *child* process. */
    }
     

    Yes fork() and exec() are the most direct access you get, it's the
    bare kernel API without any overhead. You should really have a look
    at some Unix programmer's book for a hint at all the details and
    tricks that can be done with this simple-looking functions.

    Depending on your application, you can also use apple events to ask
    the Finder to start a GUI application for you (which is probably what
    the "open" tool does) or, in a Cocoa app, you can use the NSTask
    class.


    benny
    Benjamin Guest

  3. #3

    Default Re: Need advice to launch an application from C tool ?

    On Fri, 28 Nov 2003, Benjamin Riefenstahl wrote:
     
    >
    > ??
    >
    > "open -a /theApplication" *is* a shell script, it's not a path to one.
    > If you actually want to execute a shell script like that, use the
    > system() function:
    >
    > const char script[] = "open -a /theApplication";
    > system(script);
    >
    > As with all shell scripting, be carefull to quote the parameters
    > correctly, like e.g.:
    >
    > const char script[] = "open -a '/the Application'";
    > system(script);
    >[/ref]
    and even then you would need to escape the application's name
    (eg if the app name was myapp';rm * probably unlikely but you can never
    be too safe.) avoid system whenever possible, use one of the below
    methods.

    Fred


     
    >
    > Yes fork() and exec() are the most direct access you get, it's the
    > bare kernel API without any overhead. You should really have a look
    > at some Unix programmer's book for a hint at all the details and
    > tricks that can be done with this simple-looking functions.
    >
    > Depending on your application, you can also use apple events to ask
    > the Finder to start a GUI application for you (which is probably what
    > the "open" tool does) or, in a Cocoa app, you can use the NSTask
    > class.
    >
    >
    > benny
    >[/ref]

    Frederick Guest

  4. #4

    Default Re: Need advice to launch an application from C tool ?

    Benjamin Riefenstahl wrote:

     

    Small typo, missing the argv[0] for the new program,

    execl("/usr/bin/open", "/usr/bin/open", "-a", the_application, NULL);
    ^^^^^^^^^^^^^^^


    _ Guest

  5. #5

    Default Re: Need advice to launch an application from C tool ?

    _ <__._> writes: 
    >
    > Small typo, missing the argv[0] for the new program,
    >
    > execl("/usr/bin/open", "/usr/bin/open", "-a", the_application, NULL);[/ref]

    Yes, thanks.


    benny
    Benjamin Guest

  6. #6

    Default Re: Need advice to launch an application from C tool ?

    In article <168.1.100>,
    ca (Alain Birtz) wrote:
     

    With "plain" C, on a Unix system like Mac OS X, that's the way to do it.
    Well, it's one way. There are others, depending on what exactly you
    want to happen. See, for example, doentation on popen() or system().

    Apple's frameworks provide alternatives-- in Cocoa you can use NSTask,
    or -[NSWorkspace launchApplication:].

    --
    Tom "Tom" Harrington
    Macaroni, Automated System Maintenance for Mac OS X.
    Version 1.4: Best cleanup yet, gets files other tools miss.
    See http://www.atomicbird.com/
    Tom Guest

Similar Threads

  1. Windows remote application launch through a Web service
    By pberna in forum ASP.NET Web Services
    Replies: 0
    Last Post: July 28th, 06:45 PM
  2. Application Launch Failure
    By Abel_Teo@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 9
    Last Post: April 23rd, 06:01 PM
  3. Could not launch external image application
    By Rene_Perales@adobeforums.com in forum Adobe Illustrator Windows
    Replies: 1
    Last Post: April 7th, 04:41 PM
  4. could not launch external image editing application
    By Shaun_College@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 3
    Last Post: April 2nd, 04:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139