diff --git a/commands.cpp b/commands.cpp index 62f1942..06ece75 100644 --- a/commands.cpp +++ b/commands.cpp @@ -124,7 +124,7 @@ void PendingCmd::cancel() execed_ = true; } -str $(const PendingCmd& cmd) +std::string $(const PendingCmd& cmd) { RetProc p = const_cast(cmd).runRedir(); @@ -134,7 +134,7 @@ str $(const PendingCmd& cmd) ioctl(p.out, FIONREAD, &pipe_size); // write to the string directly, todo: find a better way - str output; + std::string output; output.resize(pipe_size); read(p.out, (char*)output.c_str(), output.size()); return output; diff --git a/commands.hpp b/commands.hpp index d200f07..b42a636 100644 --- a/commands.hpp +++ b/commands.hpp @@ -143,16 +143,17 @@ PendingCmd& operator<(const PendingCmd&, fd_t); this is not possible */ PendingCmd operator&(const PendingCmd&, const Cmd&); +// todo /* string that is implicitly cast to const char* and doesn't deallocate to allow for simpler synthax, speed and safety e.g: echo + some_string rather then: echo + some_string.c_str() */ -class LeakStr: public std::basic_string /* todo: allocator */ -{ -public: - using std::basic_string::basic_string; - operator const char*() { return c_str();} -}; +// class str: public std::basic_string /* todo: allocator */ +// { +// public: +// using std::basic_string::basic_string; +// operator const char*() { return c_str();} +// }; /* Execute a command and capture the output shell: @@ -160,4 +161,4 @@ public: becomes: auto var = $(ls); */ -LeakStr $(const PendingCmd&); +std::string $(const PendingCmd&); diff --git a/test.cpp b/test.cpp index 0478174..bd169ac 100644 --- a/test.cpp +++ b/test.cpp @@ -15,8 +15,8 @@ int main() Cmd echo("echo"); Cmd rm("rm"); - str out1 = $(ll | grep + "cpp" | grep + "child"); - if(out1.find("childProcess.cpp") != str::npos) + string out1 = $(ll | grep + "cpp" | grep + "child"); + if(out1.find("childProcess.cpp") != string::npos) cout << "OK 0/11" << endl; Cmd success("echo", "OK 1/11"); @@ -53,5 +53,6 @@ int main() // wait for all detached while(wait(nullptr) != -1); - exec( echo + $(echo + "OK 11/11") ); + // todo + // exec( echo + $(echo + "OK 11/11") ); }