Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

unknown.exe

macrumors member
Original poster
Sep 22, 2007
67
0
Somewhere on Earth
Sup, I'm writing a C++ program that has all of these built in programs(just simple conversion or game progs), and I'm putting one in that opens up external programs like Safari or Word. I know how to do it in windows (#include <stdlib.h>... system("C:\\folder\\program.exe"). But SYSTEM doesn't work in mac or xcode... please can someone tell me how to do this?:apple:
 

Cromulent

macrumors 604
Oct 2, 2006
6,810
1,100
The Land of Hope and Glory
Sup, I'm writing a C++ program that has all of these built in programs(just simple conversion or game progs), and I'm putting one in that opens up external programs like Safari or Word. I know how to do it in windows (#include <stdlib.h>... system("C:\\folder\\program.exe"). But SYSTEM doesn't work in mac or xcode... please can someone tell me how to do this?:apple:

system("/path/to/executable");
 

unknown.exe

macrumors member
Original poster
Sep 22, 2007
67
0
Somewhere on Earth
system("Macintosh HD/Applications/VLC");
this is what I have in my program, but it says
sh: line 1: Macintosh:command not found
i tried using my home directory...
system ("markspangler/Applications/VLC");
but it tells me "no such directory"....
any more help?
(do i need a specific #include file?)
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If you want to open Safari, use this:

Code:
system("open /Applications/Safari.app");

The "open" command works as if you double-clicked the file.

If you were to use this instead:

Code:
system("/Applications/Safari.app/Contents/MacOS/Safari");

You would get a new instance of Safari. Much like opening multiple instances of IE in Windows. But this isn't Mac behavior so use "open" instead.
 

Cromulent

macrumors 604
Oct 2, 2006
6,810
1,100
The Land of Hope and Glory
Excuse me, but what do you mean? Like system("Macintosh HD/Applications/Word")................or are there technical terms I need to use like C:\ drive in windows? Like a technical name for the HD?

Unix based operating systems have a different path structure to Windows.

So C:\Stuff\Random\test.exe is exactly the same as /Stuff/Random/test.app in Mac OS X.

Edit : To clarify. The root of the hard drive in Windows is C: the root of the hard drive in OS X is /. All full paths in OS X start with / as all full paths in Windows start with C:\.
 

tiikeli

Guest
Dec 1, 2007
1
0
Invokes the command processor to execute a command. Once the command execution has terminated, the processor gives the control back to the program, returning an int value, whose interpretation is system-dependent.

Is this _really_ what you want to do? The normal way would be to fork the process and then call one of the exec functions, eg. execve.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
system("Macintosh HD/Applications/VLC");
this is what I have in my program, but it says
sh: line 1: Macintosh:command not found
i tried using my home directory...
system ("markspangler/Applications/VLC");
but it tells me "no such directory"....
any more help?
(do i need a specific #include file?)

This doesn't work, because what the system sees is the line

Macintosh HD/Applications/VLC

which is interpreted as the command "Macintosh" with a parameter "HD/Application/VLC". Using the "system" command is difficult and can be extremely dangerous. The same code would also not work on any computer where the hard disk isn't called "Macintosh HD".

Typing "LaunchApplication" into spotlight should show you a document "Launch Services Reference", which contains the recommended way to launch applications. For example, the call "LSOpenItemsWithRole" will "open" any number of items, including applications, as if you had double-clicked their icon, and it will do the Right Things.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.