PDA

View Full Version : Executing files with C++ under Linux


oracleguy
12-29-2006, 06:56 AM
I am working on a program and I'm trying to execute files from my C++ application. Like run their default action.

Under Windows I am using the shell execute API to do it, e.g.
HINSTANCE rcode;
rcode = ShellExecuteA( NULL, "open", "relnotes.htm", NULL, "", SW_SHOW );

But I can't seem to find out how to do it under Linux. I found execve (http://www.die.net/doc/linux/man/man2/execve.2.html) however that is for other applications or scripts. I'm going for among other things opening .htm files in the default browser.

Anyone have any ideas?

xconspirisist
12-30-2006, 12:37 AM
I believe the C stdlib has something like this. I'm sorry that I can't be more specific, because I havn't done this in rather a while. If I remember correctly, it is something like "sys()" or "system()".

oracleguy
12-30-2006, 02:53 AM
Yeah, I guess I should of mentioned that, the system() method won't work.

xconspirisist
12-30-2006, 04:43 AM
For what reason?

oracleguy
12-30-2006, 10:44 AM
If you go to the shell in Linux and type 'relnotes.htm' it is an invalid command.

oracleguy
01-13-2007, 06:41 PM
Just in case anyone wants to know in the future, I figured out how to do it if the user is running KDE:
system("kfmclient exec relnotes.htm");