Public Group

# Running an application from within another application - C++

This topic is 4409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've always wondered- how do you run another application from inside an application (i.e. what's the command from application1 to run application2?). Also, if you have an answer, could you also include how to send it parameters? Thanks :)

##### Share on other sites
I'm not sure if it can be ran from within it, rather than starting a seperate application.

C++ allows for certain lamguages to be embdedded into its code, which si read from a file, and ran right then and there. Trhe advantage to this, is might whaty ou already thought; breaking up a large application by including seperate applications/scripts that can be changed/modified without recompiling the whole huge project.

Some languages are Lua, Ruby, I believe LISP and Python(not sure).

##### Share on other sites
the answer to this depends entirely on the platform and environment you are using, as there are different ways to accomplish this which may not be feasible in some contexts-if you are interested in the Win32 solution, make sure to check out the MSDN documentation for "ShellExecute", for *nix development, you'll want to look into functions such as "exec".

However, in general one of the most portable solutions is to simply use the "system" call:

#include <cstdio> //not necessarily required-depends on your compiler/OS etc#include <cstdlib>int main(){using namespace std;char *cmd="dir /p"; // simply add parameters to the stringsystem(cmd);return 0;}

HTH

##### Share on other sites
So the "dir" part is the application itself, and then just list the paramaters, correct?

I forgot to mention that I'm using Windows, although the application I want to run is a console app that I'm using for internet-related tasks.

Thanks for the quick response. I really appreciate it.

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632912
• Total Posts
3009182
• ### Who's Online (See full list)

There are no registered users currently online

×