运行另一个c ++程序的C ++程序

时间:2014-02-21 14:55:47

标签: c++ mutation-testing

我想创建一个c ++程序,将程序写入文件然后运行它。目标是制作一些随机数字生成器或类似的东西,测试每一个并做一些像算法的“自然选择”以获得最终更好的(并且可能重复该过程)。

我对AI部分不感兴趣。我只想知道运行另一个c ++程序的c ++程序是否可行,以及它是如何实现的。

感谢您的支持!

2 个答案:

答案 0 :(得分:1)

int result = system("another_program");

这是reference

答案 1 :(得分:0)

您可以使用CreateProcess WinAPI启动您需要的所有其他程序:

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
wchar_t command[MAX_PATH];
swprintf_s(command, L"path to whatever program you need");

// Start the child process. 
if( !CreateProcess( NULL,   // No module name (use command line)
    command,        // Command line
    NULL,           // Process handle not inheritable
    NULL,           // Thread handle not inheritable
    FALSE,          // Set handle inheritance to FALSE
    0,              // No creation flags
    NULL,           // Use parent's environment block
    NULL,           // Use parent's starting directory 
    &si,            // Pointer to STARTUPINFO structure
    &pi )           // Pointer to PROCESS_INFORMATION structure
  ) 
{
    MessageBox(NULL, L"Could not start program", L"Error", MB_OK | MB_ICONERROR);
}
相关问题