2 * Copyright (C) 2010-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <json/json.h>
25 static char *task_exec(char *opts)
29 char *str, *tmp, *cmd, buf[1024];
33 cmd = malloc(strlen("task rc.json.array=on ") + strlen(opts) + 1);
34 strcpy(cmd, "task rc.json.array=on ");
46 while ((s = fread(buf, 1, 1024, f))) {
47 tmp = malloc(strlen(str) + s + 1);
48 memcpy(tmp, str, strlen(str));
49 memcpy(tmp + strlen(str), buf, s);
50 tmp[strlen(str) + s] = '\0';
58 printf("pclose fails\n");
68 static struct json_object *task_exec_json(char *opts)
70 struct json_object *o;
73 str = task_exec(opts);
76 o = json_tokener_parse(str);
84 int main(int argc, char **argv)
86 struct json_object *o;
88 o = task_exec_json("export");
90 printf("%s\n", json_object_to_json_string(o));