Advertisement
renix1

Read command function

Sep 13th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. char *read_command(char *command) {
  6.     FILE *fp;
  7.     char *output;
  8.     output = malloc(10);
  9.     fp = popen(command, "r");
  10.     if (fp == NULL) {
  11.         exit(1);
  12.     } else {
  13.         fscanf(fp, "%s", output);
  14.     }
  15.     pclose(fp);
  16.     return output;
  17. }
  18.  
  19.  
  20. int main() {
  21.     char *out;
  22.     out = read_command("xdotool getwindowname $(xdotool getactivewindow)");
  23.     printf("Active Window => %s\n", out);
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement