SystemRun.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <string>
  2. #include "SpBase.h"
  3. #include "toolkit.h"
  4. void SystemRunTest(const std::string& systemCmd)
  5. {
  6. LOG_FUNCTION();
  7. #if 0
  8. std::string succStr, errStr;
  9. std::string runStr(systemCmd);
  10. if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
  11. if (succStr.empty()) {
  12. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("result empty");
  13. } else {
  14. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ret msg: %s", succStr.c_str());
  15. }
  16. } else {
  17. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute '%s' failed!", runStr.c_str());
  18. }
  19. #else
  20. do {
  21. char app[2048] = { '\0' };
  22. char szldPath[1024] = { '\0' };
  23. size_t szldLen = 1023;
  24. tk_process_t* process = NULL;
  25. tk_process_option_t option;
  26. const int ldRet = toolkit_getenv("LD_LIBRARY_PATH", szldPath, &szldLen);
  27. option.exit_cb = NULL;
  28. option.file = NULL;
  29. option.flags = 0;
  30. sprintf(app, "%s", systemCmd.c_str());
  31. option.params = app;
  32. if (ldRet == 0) {
  33. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get library path: %s", szldPath);
  34. toolkit_unsetenv("LD_LIBRARY_PATH");
  35. } else {
  36. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetEnv of LD_LIBRARY_PATH failed: %s", toolkit_strerror(ldRet));
  37. }
  38. const int res = process_spawn(&option, &process);
  39. if (0 == res) {
  40. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute {%s} suc pid: %d", app, process->pid);
  41. FREE(process);
  42. } else {
  43. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute {%s} failed: %d", app, res);
  44. }
  45. if (ldRet == 0) {
  46. toolkit_setenv("LD_LIBRARY_PATH", szldPath);
  47. }
  48. } while (false);
  49. #endif
  50. }