'C++ execute bat/sh file and choose variant from UI

Faced a problem during the implementation of the launch of the script under the UI in C++ with SDL2.

The task is that a script is launched by pressing a button in the UI. Further, the option should be selected in the script (entering the number in the console, in the script), but I cannot do this by pressing the button. The script is run as system("script.bat") through a separate thread to avoid blocking the UI.

Further, according to the script's logic, a number should be entered and enter is pressed, but here I don’t know how to do it. Tried system("echo 1\n") and std::cout << "1" << std::endl doesn't work. Maybe I should implement this in another way?

Buttons code:

    if (ui::Button().text("Start script"))
    {
        m_thread = std::thread([this]() { // in thread to avoid blocking the UI
            system("script.bat");
        });
    }

    if (ui::Button().text("Variant 1"))
    {
        system("echo 1\n");
        std::cout << 1 << std::endl;
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source