summaryrefslogtreecommitdiff
path: root/slstatus.c
diff options
context:
space:
mode:
authorAaron Marcher <info@nulltime.net>2016-08-15 12:23:35 +0200
committerAaron Marcher (drkhsh) <info@nulltime.net>2016-08-15 12:23:35 +0200
commitf6f0c895ce95065f581f6f6d473afe9745a6f812 (patch)
tree1bee68693cd630c6ddad032a322c3eec114cd36b /slstatus.c
parent3c1a03919f147069fac3444f5c8a2adaf8a65478 (diff)
Added shell command function
Diffstat (limited to 'slstatus.c')
-rw-r--r--slstatus.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/slstatus.c b/slstatus.c
index 6d56000..a5807dd 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -444,6 +444,32 @@ ram_used(const char *null)
return smprintf("%f", (float)used / 1024 / 1024);
}
+/* custom shell command */
+char *
+run_command(const char* command)
+{
+ FILE *fp;
+ char buffer[64];
+
+ /* try to open the command output */
+ if (!(fp = popen(command, "r"))) {
+ fprintf(stderr, "Could not get command output for: %s.\n", command);
+ return smprintf("n/a");
+ }
+
+ /* get command output text, save it to buffer */
+ fgets(buffer, sizeof(buffer)-1, fp);
+
+ /* close it again */
+ pclose(fp);
+
+ /* add nullchar at the end */
+ buffer[strlen(buffer) - 1] = '\0';
+
+ /* return the output */
+ return smprintf("%s", buffer);
+}
+
/* temperature */
char *
temp(const char *file)