-2

Please, I need a simple code example showing how to run an .exe program with parameters from inside my C++ program.

Something like:

myExternal program
int main (int a , int b)
{
    int c = a+b;
    return c;
}

My Caller program looks like this:

int Caller_main ()
{
    execute( myExternalprogram.exe, (with parameters 5 and 6!));
    get (the result!);
}
A. Colina
  • 1
  • 2
  • Does this answer your question? [How do i open a program in a separate terminal from c++ code?](https://stackoverflow.com/questions/43342796/how-do-i-open-a-program-in-a-separate-terminal-from-c-code) – dtell Apr 05 '20 at 18:29
  • And this is how to use `argc` and `argv`: https://www.thegeekstuff.com/2013/01/c-argc-argv/ – fas Apr 05 '20 at 18:29
  • This is a duplicate to this: [https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po#478960](https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po#478960) – aliberro Apr 05 '20 at 18:42
  • Note: while it's not impossible, it is unusual for main to accept a pair of `int`s. Typically `main` accepts either nothing or a count and an array of strings of size specified by the count. – user4581301 Apr 05 '20 at 19:07

1 Answers1

1

Have you tried using system()? std::system("command"). Something like:

std::string myCmd = "myExternalprogram.exe abc 123"; // Obviously append the parameters
std::system(myCmd.c_str());
theWiseBro
  • 1,439
  • 12
  • 11