I was using system() function
"int system ( const char * command );”
for executing an executable external program from CPP program.
I want to give absolute and relative Path to the folder where executable was present. I was using/calling the system function in the program name “testExt.cpp”
Then compile using g++
c:\> g++ -g testExt.cpp -o teste
then ran the executable file “teste.exe” which we compiled above.
dir: C:blabla: No such file or directory
C:blablaxyz.exe: not found
You will notice one very surprising thing in that the backslash is not present in any of the command output. So, it will not follow the exact PATH you mentioned in the program. Even you try to write your path like this to fix the problem.
It will still not help as it will still give different error message ‘not found’ instead of correct path and correct name of executable. Following the error message from the above another way of writing Path to the executable
C:\blabla\xyz.exe: not found
The main reason behind is that g++ compiler understand path in terms of UNIX/LINUX based system. So, lets re write “testExt.cpp” Program.
Recompile the program using g++ like we did above and run the executable.
BAAAAM!!! It worked!!! you can see the content of the folder ‘blabla’ and your executable ‘xyz.exe’ is called from your recompiled program.
The new re-written program starts with ‘/’ which is called root in UNIX/Linux based system.
In Windows system, ‘C:\’ have to replaced by ‘/’ and write your path using FORWARD SLASH as shown in the re-written program “testExt.cpp“.
Hope this may be helpful for you. Have a nice day!!!