Back Forum Reply New

Launch program from C++

Is there any way to launch a program in C++ without using quot;system()quot;?

My application is in Qt4 and I find that the app freezes if I use that function. I would like the app to be responsive, but still wait for the other program to close.

If possible, I would like to continuously read the output of the other program (to show progress in a progressbar for example).

Any help is appretiated!

In this case you need to fork() then use execvp(quot;program_namequot;) to run the program


Code:
if (!fork()) {  // code in parent your original program
} else { execvp(quot;lsquot;, NULL);
}
Will that help? It'll be interesting to see other way too..


Originally Posted by nitro_n2oIn this case you need to fork() then use execvp(quot;program_namequot;) to run the program

Oh! Forgot to add... It needs to work on both Linux and Windows :/
I would prefer to use the same function on both... but if I have to, I'll specify different functions for Windows and Linux.

I dont think thats very possible unless you either implement a platform independent layer, or you use another library to handle that for you. Perhaps using SDL_threads or something and run system() in another thread so its running along side of the application.


Originally Posted by maddog39I dont think thats very possible unless you either implement a platform independent layer, or you use another library to handle that for you. Perhaps using SDL_threads or something and run system() in another thread so its running along side of the application.

If there is a way to do this in Windows (read the output and everything, not using fork() and execvp()) I could write headers for Windows and Linux specifying different functions (with the same name) for both systems.

Is there a way to do it in windows?

Are you going to be building your application on Windows with gcc (g++) or Microsoft's compiler?


Originally Posted by harunAre you going to be building your application on Windows with gcc (g++) or Microsoft's compiler?

I'll be building it with G++. Though I plan to (if I manage) compile it in Linux (using mingw)

I guess you meant windows.

You can use winapi from a mingw32 compiled project just as fine, so you can just have some #ifdef conditions to use that winapi call to launch a program. (Use MSDN for info about how to use winapi...)


Originally Posted by vexorianI guess you meant windows.

You can use winapi from a mingw32 compiled project just as fine, so you can just have some #ifdef conditions to use that winapi call to launch a program. (Use MSDN for info about how to use winapi...)

No, I really meant Linux. I plan on crosscompiling, unless I find someone with a Windows computer willing to set up a build environment...
I'll look into WinAPI
¥
Back Forum Reply New