This commit is contained in:
vrd
2025-06-06 18:00:38 +03:00
parent c538d70823
commit 184b211fc8
3 changed files with 17 additions and 8 deletions
+5 -2
View File
@@ -26,10 +26,10 @@ public:
/* Execute the command, if arguments are not given use stdin,out,err /* Execute the command, if arguments are not given use stdin,out,err
else use the given file desciptors. this can also be used else use the given file desciptors. this can also be used
to redirect err to out by giving err=1 like in shell */ to redirect err to out by giving err=1 like in shell */
DeadProc operator()(fd_t in=0, fd_t out=1, fd_t err=2); DeadProc operator()(fd_t in=0, fd_t out=1, fd_t err=2) const;
/* Run the command, don't wait to return like shell's & */ /* Run the command, don't wait to return like shell's & */
Proc detach(fd_t in=0, fd_t out=1, fd_t err=2); Proc detach(fd_t in=0, fd_t out=1, fd_t err=2) const;
/* Append arguments */ /* Append arguments */
void append_args(std::initializer_list<const char*>); void append_args(std::initializer_list<const char*>);
@@ -81,6 +81,9 @@ private:
/* Like shell's exec */ /* Like shell's exec */
void exec(const Cmd&); /* todo: take Pending? */ void exec(const Cmd&); /* todo: take Pending? */
/* Execute the command, like the operator() */
DeadProc run(Cmd&);
/* Run commands in sequence /* Run commands in sequence
shell: shell:
ls ls
+11 -6
View File
@@ -28,7 +28,7 @@ namespace _cppipe
} }
} }
inline DeadProc Cmd::operator()(fd_t in, fd_t out, fd_t err) inline DeadProc Cmd::operator()(fd_t in, fd_t out, fd_t err) const
{ {
Proc p = createProcess(argv.data(), in, out, err); Proc p = createProcess(argv.data(), in, out, err);
@@ -43,7 +43,7 @@ inline DeadProc Cmd::operator()(fd_t in, fd_t out, fd_t err)
return wait(p); return wait(p);
} }
inline Proc Cmd::detach(fd_t in, fd_t out, fd_t err) inline Proc Cmd::detach(fd_t in, fd_t out, fd_t err) const
{ {
return createProcess(argv.data(), in, out, err); return createProcess(argv.data(), in, out, err);
} }
@@ -154,6 +154,11 @@ inline void exec(const Cmd& cmd)
exec_or_die(cmd.argv.data()); exec_or_die(cmd.argv.data());
} }
DeadProc run(const Cmd& cmd)
{
return cmd();
}
inline PendingCmd operator,(const PendingCmd& cleft, const Cmd& right) inline PendingCmd operator,(const PendingCmd& cleft, const Cmd& right)
{ {
auto& left = const_cast<PendingCmd&>(cleft); auto& left = const_cast<PendingCmd&>(cleft);
@@ -284,9 +289,9 @@ inline PendingCmd operator&(const PendingCmd& cleft, const Cmd& right)
return PendingCmd(right); return PendingCmd(right);
} }
inline std::ostream& operator<<(std::ostream& s, const Cmd& c) inline std::ostream& operator<<(std::ostream& s, const Cmd& cmd)
{ {
for(size_t i = 0; i < c.argv.size() - 1; ++i) for(size_t i = 0; i < cmd.argv.size() - 1; ++i)
s << '"' << c.argv[i] << '"' << ' '; s << '"' << cmd.argv[i] << '"' << ' ';
return s << std::endl; return s;
} }
+1
View File
@@ -3,6 +3,7 @@ tips (sigaction SIGCHILD, SIG_IGN, SIG_DFL)
make sure file descriptors are closed when no longer used make sure file descriptors are closed when no longer used
cppipe compile options from tft cppipe compile options from tft
respect CXXFLAGS LDFLAGS respect CXXFLAGS LDFLAGS
remove append_args
? ?
run(cmd) run(cmd)