system command

I am trying to call an external application in my C++ program , example,
system("C:\Program Files\Internet Explorer\iexplore.exe");
but the application just gets closed. Can any one help me!

Dear All,
Thanks a lot. my problem is resolved.
1. double slashes need to be used. thanks for the suggestion and
2. the command that worked for me was "ShellExecuteEx"
Last edited on
I seem to recall using this in the past:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

(assuming you're on windows which it looks like you are from that path).
Quoted paths need a doubleslash for backward slashes (e.g. your path would be system("C:\\Program Files\\Internet Explorer\\iexplore.exe");)
Considering iexplore.exe is usually in the system path, this would work too (but is as dangerous as using system() in the first place: system("iexplore.exe");)

This said, you should avoid system().
It opens an entire world of flaws, many antiviruses will mark your program as a virus, and many other bad things will happen.
@mutexe: Personally, I use ShellExecute, since it is able to open arbitrary files too.
cheers ess.
i've just looked at project in my work and it was ShellExecute. OP sorry for the misinformation.
The path contains spaces; enclose it in quotes:

1
2
3
4
5
6
7
// std::system("C:\Program Files\Internet Explorer\iexplore.exe");

// either
std::system( R"( "C:\Program Files\Internet Explorer\iexplore.exe" )" ) ; // c++11

// or
std::system( " \"C:\\Program Files\\Internet Explorer\\iexplore.exe\" )" ) ;
Also something to keep in mind is that the WinAPI will normally except a forward slash '/' in place of a backslash '\' for UNC paths and neither C or C++ see those as escape characters.
Topic archived. No new replies allowed.