Run a third-party executable module with arguments and get the results from it into a text string.

Challenge:

int ierr = shell_func("ExecCmd", string exenamewithargs, string sresult);

Here:

exenamewithargs is the name of a third-party program module with arguments.

If there are spaces in the path or name or arguments, then it is written in quotation marks.

sresult is the content of the console output of this module.

Return value:

-1 is an error.

0 - successful execution of the module;


Example.

Execute a third-party software module "Tschild Process.exe " with the arguments "Argument 1" and "Argument 2" and output to the message window.


int main()

{

       string sresult;

       int ires = shell_func("ExecCmd", "\"C:\\source\\TSChild Process.exe\" \"Argumetn 1\" \"Argument 2\"", sresult);

       coutvar << sresult;

       coutvar << ires;

}


The result of executing the script in the message window:




The text of the executable module "Tschild Process.exe " in C++


//************************************************

// This exe module runs and writes on the console

//************************************************

#include <iostream>

using namespace std;

int main(int argc, char* argv[])

{

       if (argc == 2)

       {

               cout << "Hello World! " << argv[1] << "\n";

       }

       else if (argc == 3)

       {

               cout << "Hello World! " << argv[1] << " " << argv[2] << "\n";

       }

       else

       {

               cout << "No arguments\n";

       }

       return 1;

}

//***********************************************