From fc4578e0c0c1d702bfdd953ed8743befafb2eced Mon Sep 17 00:00:00 2001 From: ruanshudong Date: Mon, 30 Mar 2020 18:13:05 +0800 Subject: [PATCH] tc_port add getEnv/setEnv, exec command --- cmake/Common.cmake | 16 ++++++---------- servant/CMakeLists.txt | 2 +- servant/protocol | 2 +- util/include/util/tc_port.h | 2 ++ util/src/tc_port.cpp | 26 +++++++++++++++++++++++++- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/cmake/Common.cmake b/cmake/Common.cmake index 2f65ba5..743a099 100755 --- a/cmake/Common.cmake +++ b/cmake/Common.cmake @@ -29,15 +29,11 @@ endif() #------------------------------------------------------------- -if("${INSTALL_PREFIX}" STREQUAL "") - IF (UNIX) - set(INSTALL_PREFIX "/usr/local/tars/cpp") - ELSE() - set(INSTALL_PREFIX "c:\\tars\\cpp") - ENDIF() - - set(CMAKE_INSTALL_PREFIX ${INSTALL_PREFIX}) -endif() +IF (UNIX) + set(CMAKE_INSTALL_PREFIX "/usr/local/tars/cpp" CACHE STRING "set install path" FORCE) +ELSE() + set(CMAKE_INSTALL_PREFIX "c:\\tars\\cpp" CACHE STRING "set install path" FORCE) +ENDIF() #------------------------------------------------------------- IF (APPLE) @@ -89,7 +85,7 @@ message("CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}") message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message("PLATFORM: ${PLATFORM}") -message("INSTALL_PREFIX: ${INSTALL_PREFIX}") +message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") message("BIN: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") message("TARS2CPP: ${TARS2CPP}") #------------------------------------------------------------- diff --git a/servant/CMakeLists.txt b/servant/CMakeLists.txt index d305802..a2ee3d4 100644 --- a/servant/CMakeLists.txt +++ b/servant/CMakeLists.txt @@ -37,7 +37,7 @@ macro(complice_tars OUT_DEPENDS_LIST HEADER TARS_DIR) add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${TARS_H} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS tars2cpp ${TARS_IN} + DEPENDS tars2cpp ${FILE} COMMAND ${TARS2CPP} --with-tars ${INCLUDE} ${TARS_IN} COMMENT "${TARS2CPP} --with-tars ${INCLUDE} ${TARS_IN}") diff --git a/servant/protocol b/servant/protocol index ed2cb05..8d1993b 160000 --- a/servant/protocol +++ b/servant/protocol @@ -1 +1 @@ -Subproject commit ed2cb055d5799d45bdeeec920092ee3fccd85e2b +Subproject commit 8d1993be26db9792f581e779890fb83fec0b9de4 diff --git a/util/include/util/tc_port.h b/util/include/util/tc_port.h index ddfc481..2dd7785 100755 --- a/util/include/util/tc_port.h +++ b/util/include/util/tc_port.h @@ -66,6 +66,8 @@ public: static std::string getEnv(const std::string &name); static void setEnv(const std::string &name, const std::string &value); + + static std::string exec(const char* cmd); }; } diff --git a/util/src/tc_port.cpp b/util/src/tc_port.cpp index 2473ca6..e43abfa 100755 --- a/util/src/tc_port.cpp +++ b/util/src/tc_port.cpp @@ -189,4 +189,28 @@ void TC_Port::setEnv(const string &name, const string &value) setenv(name.c_str(), value.c_str(), true); #endif } -} \ No newline at end of file + +string TC_Port::exec(const char *cmd) +{ + string fileData; +#if TARGET_PLATFORM_WINDOWS + FILE* fp = _popen(cmd, "r"); +#else + FILE* fp = popen(cmd, "r"); +#endif + static size_t buf_len = 2 * 1024 * 1024; + char *buf = new char[buf_len]; + memset(buf, 0, buf_len); + fread(buf, sizeof(char), buf_len - 1, fp); +#if TARGET_PLATFORM_WINDOWS + _pclose(fp); +#else + pclose(fp); +#endif + fileData = string(buf); + delete []buf; + + return fileData; +} + +}