How to execute an .exe from c++ console application. I have try the following methods none have worked.
I want to run a application i have created a while back “Radio.exe”. this application reads an xml file at startup, if I manually run this application it works fine, but if run it via console application “Radio.exe” cant find the xml file?
void execute( char* path)
{
// cant find xml ?
ShellExecuteA( NULL, NULL, path, NULL, NULL, SW_SHOW );
// cant find xml ?
ShellExecute(NULL, NULL, path, NULL, NULL, SW_SHOWNORMAL);
// and also cant find xml ?
SHELLEXECUTEINFO rSEI ={0};
rSEI.cbSize=sizeof( rSEI );
rSEI.lpVerb= NULL;
rSEI.lpFile= "C:\\Users\\me\\Documents\\Radio.exe"; // = path
rSEI.lpParameters= 0;
rSEI.nShow = SW_NORMAL;
rSEI.fMask = SEE_MASK_NOCLOSEPROCESS;
ShellExecuteEx( &rSEI );
}
You need to set your working directory, lpDirectory:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx
You should probably set this up to be path relative too so you don’t have to provide an absolute path.
Example:
Assuming your program, which spawns radio.exe, is in the projects directory. YOu can provide the Radio directory as the relative path.