Hide console in C system() function, Win

a0rtega picture a0rtega · Oct 20, 2009 · Viewed 37.8k times · Source

I am coding a C program in Dev-C++, and I need to use a couple of Windows (CMD) commands. It is easy, but when the command in the system() function is executed, the program runs the console in the execution.

An example:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

    int main()
    {
      system("if not exist c:\my_docs\doc.txt (xcopy /Y doc.txt c:\my_docs\)"); // Cmd command
      system("pause");
      return 0;
    }

Exists other function, or a modification that do not shows the console?

Thanks you! Best regards.

Answer

Sergio Madrazo picture Sergio Madrazo · Oct 20, 2011

You can use WinExec("your cmd command", SW_HIDE); instead of system("cmd command").