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;
}
|