System () in C ++ without calling cmd.exe

How can I start the system ("") without showing cmd.exe?

I use the header cstdlib code :: blocks 10.5

I saw this question for C #, but I don't know C #;)

+1
source share
2 answers

I believe that you will need CreateProcess .

+6
source

I must say that the existing answer was not particularly delineated. Here you can execute commands without a new window cmd.exe.

Based on the answer of Roland Rabien and MSDN , I wrote a working function:

int windows_system(const char *cmd)
{
  PROCESS_INFORMATION p_info;
  STARTUPINFO s_info;
  LPSTR cmdline, programpath;

  memset(&s_info, 0, sizeof(s_info));
  memset(&p_info, 0, sizeof(p_info));
  s_info.cb = sizeof(s_info);

  cmdline     = _tcsdup(TEXT(cmd));
  programpath = _tcsdup(TEXT(cmd));

  if (CreateProcess(programpath, cmdline, NULL, NULL, 0, 0, NULL, NULL, &s_info, &p_info))
  {
    WaitForSingleObject(p_info.hProcess, INFINITE);
    CloseHandle(p_info.hProcess);
    CloseHandle(p_info.hThread);
  }
}

Windows. , system().

+1

All Articles