Task: program "A" should call another program "B", creating a separate process.

What library, header file contains the necessary functions to make a call to a third-party program? - first question.

In addition, the program "A" must also be passed to program "B" arguments (lines), so that they are used by program "B". How to carry out, firstly, in fact, the transfer of this information, secondly, the input of this string information in the program "B"? - second question.

Note: the source code of program "B" is unknown, its extension is .exe.

  • one
    Can you tell us what you have already tried to do to answer your question? - igumnov
  • Just tell you the direction. Google c++ system , read, and then carefully read man 3 system . (I understand that the author has Windows, but it’s better to start with POSIX). - avp pm

2 answers 2

Use Win API, specifically CreateProcces (...). I hope you can use Google. The command line arguments (here I can be wrong) can be passed through the second argument of this function, although I doubt it.

    For example, you need to run sum.exe, which receives two inta on the input and displays their sum. To do this, you can use the CreateProcess function from windows.h.

     STARTUPINFOA si; PROCESS_INFORMATION pi; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); std::string process_name("D://sum.exe"); int a = 5; int b = 10; std::string cmd_params(process_name + " " + std::to_string(a) + " " + std::to_string(b)); BOOL res = CreateProcess(NULL, const_cast<LPSTR>(cmd_params.c_str()), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi); 

    The first parameter is responsible for the process name, but it can be omitted, because the name will still be passed to the command line argument (second parameter).

    Additionally: http://vsokovikov.narod.ru/New_MSDN_API/Process_thread/fn_createprocess.htm