alternative to system()

Started by
10 comments, last by CProgrammer 20 years, 9 months ago
I am making a starter program and i need a function call that opens an exe file. I know one can use system() but i was wondering wether there is a function call that opens the exe directly without an MS-DOS window. -CProgrammer
Advertisement
exec()?
CreateProcess()?

Depends whether you want to use windows or POSIX..
Take a look at CreateProcess.

You might also look at WinExec, but that is really only around for backward compatibility.
popen() too.

--edit--

man popen

[edited by - Leffe on July 3, 2003 2:29:19 PM]
i think ill look into CreateProcess thanks everybody.

-CProgrammer
ShellExecute() as well.


Qui fut tout, et qui ne fut rien
Invader''s Realm
Thanks Invader
Ok i used ShellExecute in my app which worked fine.
However say im executing "Data/app.exe" when i do this the application app.exe assumes that it is in the same directory as the primary application it is however in ''Data''. All Data that app.exe now loads like "settings.ini" would need to be renamed to "Data/settings.ini" which in this case is not an option.
How can i solve this problem?
Never open files with a relative path unless you have a good reason to. Always build a complete absolute path.

Use GetModuleFileHandle( NULL ) and remove your exe file name.
Use that path for opening your files from. It may be a bit more work to do but it pays off. You can call your app any possible way and it will find it''s files.

(Note: Talking Windows here)

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

So am i getting this right?
I can''t find GetModuleFileHandle but assume GetModuleHandle will give me the path of the exe running.
So if i append for instance "Data/app.exe" to the string after truncating the exe file part i have the absolute path.
Now if i use ShellExecute with the absolute address my app will find its files?
Well i tryed writng the entire path into the code by hand and it didnt work. Maybe you could explain this in a bit more detail.
Thanks
-CProgrammer

This topic is closed to new replies.

Advertisement