Re: [Dev-C++] capture command line output
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Reid T. <rei...@at...> - 2005-10-18 03:08:19
|
Noorez Kassam wrote:
> I have a GUI program that calls on another command line program to
> perform a task on a file, but how do i capture the results of the
> command line output so that i can use it in my GUI and display it to
> the user?
simplistic example...
$cat popentst.c
#include <stdio.h>
#include <stdlib.h>
main()
{
char *cmd = "/usr/bin/ls *.c";
char buf[BUFSIZ]; /* BUFSIZ is declared in my stdio.h to be 1024 */
FILE *ptr;
if ((ptr = popen(cmd, "r")) != NULL)
while (fgets(buf, BUFSIZ, ptr) != NULL)
(void) printf("%s", buf);
(void) pclose(ptr);
return 0;
}
|