Another pointless question - launching apps from your app

Discussion in 'Mac Programming' started by kristiaand, Dec 12, 2007.

  1. kristiaand macrumors member

    Dec 5, 2007
    Hi all,
    as mentioned i have some programming skill in another language on windows (borland delphi), and often when i was looking for answers on forums to problems, i would see hundreds of threads like this one, so here goes (man i feel like such a fool)

    how do i launch another application from within my cocoa app?

    specifically i would like to launch the terminal (hidden if possible) and pass it a command.

    i am looking to call SMBClient and pass it a set of parameters to "automatically" mount a network share, i did have a sample app that launched programs but in my wild stupidity i have managed to loose it....

    when i tried [open "smbclient <params>", 0] Xcode went crackers with errors...
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    You can launch apps via the NSWorkspace launchApplication method.

    But that's not what you actually want to do. You want to launch a Unix task and interact with it. So you want NSTask.

    You might want to read this very helpful article on wrapping Unix commands using NSTask.
  3. yeroen macrumors 6502a


    Mar 8, 2007
    Cambridge, MA
    At the BSD-layer: fork() (or vfork() ) followed by one of the exec () family of functions (execl, execlp, execle, execv, execve, execvp, execvP)...

    Although you can probably do this all in one shot at some Apple-provided Core/Cocoa layer..I don't know what's there off the top of my head.
  4. Krevnik macrumors 68040


    Sep 8, 2003
    NSTask? :D

Share This Page