diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/print_cmd.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/print_cmd.c b/src/print_cmd.c new file mode 100644 index 0000000..a7ac575 --- /dev/null +++ b/src/print_cmd.c @@ -0,0 +1,23 @@ +// vim:ts=4:sw=4:expandtab +#include <stdio.h> +#include <string.h> +#include <yajl/yajl_gen.h> +#include <yajl/yajl_version.h> + +#include "i3status.h" + +void print_cmd(yajl_gen json_gen, char *buffer, const char *cmd) { + char *outwalk = buffer; + char path[1024]; + FILE *fp; + fp = popen(cmd, "r"); + fgets(path, sizeof(path) - 1, fp); + pclose(fp); + + char *nl = index(path, '\n'); + if (nl != NULL) { + *nl = '\0'; + } + maybe_escape_markup(path, &outwalk); + OUTPUT_FULL_TEXT(buffer); +} |