Using the popen () function:
http://pubs.opengroup.org/onlinepubs/009604499/functions/popen.html
The popen () function must execute the command indicated by the string command. It must create a channel between the calling program and the executed command, and must return a pointer to a stream that can be used to read or write to the channel.
#include ...
FILE *fp; int status; char path[PATH_MAX]; fp = popen("ls *", "r"); if (fp == NULL) ; while (fgets(path, PATH_MAX, fp) != NULL printf("%s", path);
This works on Linux. Therefore, I think it can also work in windows.
source share