I can run the following command
xwd -root | xwdtopnm | pnmtojpeg > screen.jpg
in a terminal under linux and it will produce a screenshot of my current screen.
I try to do the following with the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fpipe;
char *command="xwd -root | xwdtopnm | pnmtojpeg";
char line[256];
if ( !(fpipe = (FILE*)popen(command,"r")) )
{ // If fpipe is NULL
perror("Problems with pipe");
exit(1);
}
while ( fgets( line, sizeof line, fpipe))
{
//printf("%s", line);
puts(line);
}
pclose(fpipe);
}
then I compile and run the program ./popen > screen.jpg
but the resulting file screen.jpg is unrecongizable. How can I do this so that I can pipe through my program correctly?