#include #include "SpBase.h" #include "toolkit.h" void SystemRunTest(const std::string& systemCmd) { LOG_FUNCTION(); #if 0 std::string succStr, errStr; std::string runStr(systemCmd); if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) { if (succStr.empty()) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("result empty"); } else { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ret msg: %s", succStr.c_str()); } } else { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute '%s' failed!", runStr.c_str()); } #else do { char app[2048] = { '\0' }; char szldPath[1024] = { '\0' }; size_t szldLen = 1023; tk_process_t* process = NULL; tk_process_option_t option; const int ldRet = toolkit_getenv("LD_LIBRARY_PATH", szldPath, &szldLen); option.exit_cb = NULL; option.file = NULL; option.flags = 0; sprintf(app, "%s", systemCmd.c_str()); option.params = app; if (ldRet == 0) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get library path: %s", szldPath); toolkit_unsetenv("LD_LIBRARY_PATH"); } else { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetEnv of LD_LIBRARY_PATH failed: %s", toolkit_strerror(ldRet)); } const int res = process_spawn(&option, &process); if (0 == res) { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute {%s} suc pid: %d", app, process->pid); FREE(process); } else { DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute {%s} failed: %d", app, res); } if (ldRet == 0) { toolkit_setenv("LD_LIBRARY_PATH", szldPath); } } while (false); #endif }