diff options
Diffstat (limited to 'services/unix_exec_service/main.cpp')
-rw-r--r-- | services/unix_exec_service/main.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/services/unix_exec_service/main.cpp b/services/unix_exec_service/main.cpp index ad7da1f..331c98f 100644 --- a/services/unix_exec_service/main.cpp +++ b/services/unix_exec_service/main.cpp @@ -58,8 +58,21 @@ void * shell_exec(void * t) cmd = c; if(!cmd.empty()) { + FILE *f = popen(cmd.c_str(), "r"); + if(f) + { + std::string *ret = new std::string; + char buf[128]; + while(fgets(buf, 128, f)) + ret->append(buf); + return (void*)ret; + } + else + { + //TODO: handle fail (need to extend service api ?) + } } - return NULL; + return (void*)new std::string; } void load_cmds() @@ -99,15 +112,17 @@ void load_cmds() p1++; descr = str.substr(p1); } + service_info::command c; if(!_alias.empty()) { alias a; a._alias = _alias; a.cmd = cmd; + c.command = _alias; aliases.push_back(a); } - service_info::command c; - c.command = cmd; + else + c.command = cmd; c.description = descr; cmds.push_back(c); // printf("%s | %s | %s\n", _alias.c_str(), cmd.c_str(), descr.c_str()); @@ -123,7 +138,7 @@ services(get_services) { service_info shell_exec_service; shell_exec_service.acc = ACC_CHAR_PTR; - shell_exec_service.ret = RET_STD_STRING; + shell_exec_service.ret = RET_STD_STRING_PTR; shell_exec_service.name = "Shell exec"; shell_exec_service.description = "Run shell command and return output"; shell_exec_service.exec = &shell_exec; |