C++/Executing a program from another program
Expert: Eddie - 1/13/2009
QuestionHow to execute a program from another program? For example: i want to execute "START.cpp" from "MAIN.cpp". I do not want to use .exe file directly.Instead i want to execute "START.cpp" from "MAIN.cpp".
AnswerHello krutthika, thank you for the question.
A .cpp file is nothing more than a text file. It cannot be executed by itself. You have to let the compiler parse the text, generate machine code, and then link it into an executable, which can then be run on Windows machines.
If your goal is to call 1 executable file from another, then you should compile each of your source files into separate applications. Then, in the program you wish to call the others from, you can use a C function called "system()". It takes an executable file as a parameter.
Here is an example:
// Let's call the Windows built in calculator from our program
// in main.cpp
int main()
{
system("calc.exe");
return 0;
}
Please note that unless the directory your executable file is in is in your system's PATH environment variable, you will need to use an absolute path.
I hope this information was helpful.
- Eddie