简体   繁体   中英

how can i run pipe with execl and write result to file?

I try to do something like this in C but I don't know how:( :

$: xwd -silent -root | convert xwd:- -crop 1920x1080+0+0 test.png

with execl.

Now I can do only something like that:

      #include <unistd.h>
      #include <sys/types.h>
      #include <sys/stat.h>
      #include <fcntl.h>
      #include <stdio.h>
      
      int main(int argc, char *argv)
      {
          char *binaryPath = "/usr/bin/xwd";
          char *arg1 = "-root";
          char *arg2 = "-silent";
      
          int fd; /*file descriptor to the file we will redirect ls's output*/
      
          if((fd = open("xwd1.xwd", O_RDWR | O_CREAT , 0666))==-1){ /*open the file */
              perror("open");
              return 1;
          }
      
          dup2(fd,STDOUT_FILENO); 
          dup2(fd,STDERR_FILENO); 
          close(fd); 
          execl( binaryPath , binaryPath ,arg1,arg2, (char *) 0 );
      
          return 0;
      }

It writes screen dump to file xwd1.xwd but I don't know how make pipe with convert. Thanks for all the information and help.

I've resolved my problem:). I've made something like that:

 system("xwd -silent -root | convert xwd:- -crop 1920x1080+0+0 test.tiff");

thank you for all comments Kris

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM