How to run a a program from within a program (compile another program)

So i have a executable that i have that writes to certain header files storing variables and stuff, then this file is moved to another folder with source to another program.
What i want is a program to call in my compiler (g++) and compile this source and stuff without the user having to having to hand compile from aterminal, a simple execute this program with a click and the compiling is done without typing. But i would i be abble to call my compiler in the c++ code
how would i be able to write "g++ sourcefile.cpp -o outputtedexecutable">
I've heard system is unsafe
You asked how to make it work. system is unsafe in that it could be exploited.

I would use a DOS bat file to call your C++ program, compiler, scripts...
What particular problem are you trying to solve with this approach? Usually programs stay the same and just load data from files. (i.e. what is the "stuff" -- variable could obviously just be read from file.)

Andy

PS The WinAPI function which loosely corresponds to Linux's fork() is CreateProcess.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx
See MSDN or search this forum (and further afield) for example use.
Last edited on
Topic archived. No new replies allowed.