My slstatus configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
479 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "../util.h"
  6. const char *
  7. run_command(const char *cmd)
  8. {
  9. char *p;
  10. FILE *fp;
  11. if (!(fp = popen(cmd, "r"))) {
  12. fprintf(stderr, "popen '%s': %s\n", cmd, strerror(errno));
  13. return NULL;
  14. }
  15. p = fgets(buf, sizeof(buf) - 1, fp);
  16. pclose(fp);
  17. if (!p) {
  18. return NULL;
  19. }
  20. if ((p = strrchr(buf, '\n'))) {
  21. p[0] = '\0';
  22. }
  23. return buf[0] ? buf : NULL;
  24. }