error append
This commit is contained in:
@@ -1,2 +1,18 @@
|
||||
Library for easy shell like syntax and command execution in C++.
|
||||
Cppipe allows you to write and execute script like C++ programs.
|
||||
It offers a shell like synthax for seamless command execution.
|
||||
|
||||
In this way your scripts can benefit from increased control and speed, while
|
||||
maintaining a lot of the potential for simple command callsynthax.
|
||||
|
||||
INSTALLATION:
|
||||
In terminal use:
|
||||
sudo ./install.sh
|
||||
|
||||
HOW TO WRITE A CPPIPE PROGRAM:
|
||||
Just include <cppipe/commands.hpp>
|
||||
|
||||
HOW TO EXECUTE A CPPIPE PROGRAM:
|
||||
In terminal use:
|
||||
cppipe my_cppipe_program.cpp
|
||||
|
||||
|
||||
|
||||
+13
-1
@@ -130,7 +130,8 @@ str $(const PendingCmd& cmd)
|
||||
|
||||
// check output size (not portable?)
|
||||
int pipe_size;
|
||||
int rc = ioctl(p.out, FIONREAD, &pipe_size); assert(rc==0);
|
||||
// int rc = ioctl(p.out, FIONREAD, &pipe_size); assert(rc==0);
|
||||
ioctl(p.out, FIONREAD, &pipe_size);
|
||||
|
||||
// write to the string directly, todo: find a better way
|
||||
str output;
|
||||
@@ -244,6 +245,16 @@ PendingCmd& operator>=(const PendingCmd& ccmd, fd_t fd)
|
||||
return cmd;
|
||||
}
|
||||
|
||||
PendingCmd& operator>>=(const PendingCmd& cmd, const char* file)
|
||||
{
|
||||
fd_t fd = open_or_die(file, O_WRONLY | O_CREAT | O_APPEND);
|
||||
return cmd >= fd;
|
||||
}
|
||||
PendingCmd& operator>>=(const PendingCmd& cmd, fd_t fd)
|
||||
{
|
||||
return cmd >= fd;
|
||||
}
|
||||
|
||||
PendingCmd& operator<(const PendingCmd& cmd, const char* file)
|
||||
{
|
||||
fd_t fd = open_or_die(file, O_RDONLY);
|
||||
@@ -253,6 +264,7 @@ PendingCmd& operator<(const PendingCmd& ccmd, fd_t fd)
|
||||
{
|
||||
auto& cmd = const_cast<PendingCmd&>(ccmd);
|
||||
assert(cmd.in == 0 || !"ERROR: Input is already redirected!");
|
||||
|
||||
cmd.in = fd;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
+7
-4
@@ -125,10 +125,13 @@ PendingCmd& operator>(const PendingCmd&, fd_t);
|
||||
/* Same but append rather then truncate the file */
|
||||
PendingCmd& operator>>(const PendingCmd&, const char* file);
|
||||
PendingCmd& operator>>(const PendingCmd&, fd_t);
|
||||
|
||||
/* Redirect errors to file */
|
||||
PendingCmd& operator>=(const PendingCmd&, const char* file);
|
||||
PendingCmd& operator>=(const PendingCmd&, fd_t);
|
||||
/* todo >>= */
|
||||
/* Same but append rather then truncate the file */
|
||||
PendingCmd& operator>>=(const PendingCmd&, const char* file);
|
||||
PendingCmd& operator>>=(const PendingCmd&, fd_t);
|
||||
|
||||
/* Shell oprator < use file as input */
|
||||
PendingCmd& operator<(const PendingCmd&, const char* file);
|
||||
@@ -144,7 +147,7 @@ PendingCmd operator&(const PendingCmd&, const Cmd&);
|
||||
to allow for simpler synthax, speed and safety
|
||||
e.g: echo + some_string
|
||||
rather then: echo + some_string.c_str() */
|
||||
class str: public std::basic_string<char> /* todo: allocator */
|
||||
class LeakStr: public std::basic_string<char> /* todo: allocator */
|
||||
{
|
||||
public:
|
||||
using std::basic_string<char>::basic_string;
|
||||
@@ -155,6 +158,6 @@ public:
|
||||
shell:
|
||||
var=$(ls)
|
||||
becomes:
|
||||
string var = $(ls);
|
||||
auto var = $(ls);
|
||||
*/
|
||||
str $(const PendingCmd&);
|
||||
LeakStr $(const PendingCmd&);
|
||||
|
||||
Reference in New Issue
Block a user