minor change

This commit is contained in:
vrd
2023-10-10 13:59:11 +03:00
parent 105d9e5802
commit 275dc6ddae
3 changed files with 14 additions and 12 deletions
+2 -2
View File
@@ -124,7 +124,7 @@ void PendingCmd::cancel()
execed_ = true;
}
str $(const PendingCmd& cmd)
std::string $(const PendingCmd& cmd)
{
RetProc p = const_cast<PendingCmd&>(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;
+8 -7
View File
@@ -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<char> /* todo: allocator */
{
public:
using std::basic_string<char>::basic_string;
operator const char*() { return c_str();}
};
// class str: public std::basic_string<char> /* todo: allocator */
// {
// public:
// using std::basic_string<char>::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&);
+4 -3
View File
@@ -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") );
}