Launching an application from another process
Since you're talking about an application, you don't want to go through the file association mechanisms. They are for opening documents, images, etc. Using the appropriate application. Since you don't seem to know what to ask, I would say this is simple:
The family exec*
runs the executable directly. But note that it replaces the running process with the running application. Your launcher will stop running at this point. If you want the launcher to keep running, you want to use something that starts a subprocess. The low level way is fork/vfork
followed exec
, but it is much easier to launch the application with a help system
that will take care of all this behind the scenes. (Assuming there are no security concerns for users on the other side of the world who introduce execution paths).
If the launcher does not terminate as soon as it launches your application, you need to consider whether it will "block" until the launched application exits or launch the application asynchronously so that they then run in parallel. The launcher can also "wait" for the return value of the application to see if it succeeded, and possibly do something after that. There are ways to do all of this, but since we don't know what you need, I won't go into details.
In short: If your launcher's only job is to run the application, use execl
. If your launcher needs to do more, use system
. If none of these suit your needs, then you need to provide additional information - starting with the language your launcher is written in.
PS. Both have the advantage of generality and portability. They work for GUI and command line applications, and they will work on any Unix-like system and to some extent on Windows. You don't need to lock yourself into Cocoa for something this simple.
source to share
From OSX documentation on NSWorkspaces :
- openFile: Opens the specified file specified using the default application associated with its type.
- openURL: Opens a location at the specified URL.
With url you can also open the file on ftp or http for example.
source to share