Skip to content

Commit

Permalink
feat:1.7.12,重载util::ExecuteCmd(),添加int &ret参数,用于解决util::ExecuteCmd()函…
Browse files Browse the repository at this point in the history
…数拿不到返回值的问题
  • Loading branch information
hevake committed Feb 23, 2024
1 parent 8c9fdbf commit 43eed2c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions modules/util/execute_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ namespace util {

bool ExecuteCmd(const std::string &cmd)
{
int ret = ::system(cmd.c_str());
int ret = 0;
return ExecuteCmd(cmd, ret);
}

bool ExecuteCmd(const std::string &cmd, int &ret)
{
ret = ::system(cmd.c_str());
#if 0
LogTrace("system(\"%s\") = %d", cmd.c_str(), ret);
#endif
Expand All @@ -41,6 +47,12 @@ bool ExecuteCmd(const std::string &cmd)
}

bool ExecuteCmd(const std::string &cmd, std::string &result)
{
int ret = 0;
return ExecuteCmd(cmd, result, ret);
}

bool ExecuteCmd(const std::string &cmd, std::string &result, int &ret)
{
auto fp = ::popen(cmd.c_str(), "r");
if (fp == nullptr) {
Expand All @@ -57,7 +69,7 @@ bool ExecuteCmd(const std::string &cmd, std::string &result)
result += buff;
}

auto ret = pclose(fp);
ret = pclose(fp);
#if 0
LogTrace("popen(\"%s\") = %d, \"%s\"", cmd.c_str(), ret, buff);
#endif
Expand Down
3 changes: 3 additions & 0 deletions modules/util/execute_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ namespace tbox {
namespace util {

bool ExecuteCmd(const std::string &cmd);
bool ExecuteCmd(const std::string &cmd, int &ret);

bool ExecuteCmd(const std::string &cmd, std::string &result);
bool ExecuteCmd(const std::string &cmd, std::string &result, int &ret);

}
}
2 changes: 1 addition & 1 deletion version.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TBOX版本号
TBOX_VERSION_MAJOR := 1
TBOX_VERSION_MINOR := 7
TBOX_VERSION_REVISION := 11
TBOX_VERSION_REVISION := 12

0 comments on commit 43eed2c

Please sign in to comment.