🇧🇬🏴󠁧󠁢󠁥󠁮󠁧

cppipe - C Plus Pipe

Using cppipe in C++:

#include <cppipe/commands.hpp>   // include cppipe

int main()
{
	Cmd ls("ls");           // declare command: ls
	Cmd grep("grep");
	Cmd rm("rm", "-r");     // delcate command rm -r
	Cmd echo("echo");
	Cmd mkdir("mkdir");
	Cmd dwm("dwm");
	Cmd st("st");
	Cmd emacs("emacs");

	ls();                   // run a command

	ls | grep + ".cpp";     // shell equivalent: ls | grep .cpp

	mkdir + "test_dir",     // run commands in sequence
	rm + "test_dir";        // shell equivalent: mkdir test_dir; rm test_dir

	echo + "some text" > "f.txt";          // shell equivalent: echo some text > f.txt
	rm + "-v" > "log.txt" >= "err.txt";    // shell equivalent: rm -r -v > log.txt 2> err.txt

	grep + "error" < "err.txt";            // shell equivalent: grep error < err.txt

	Cmd check_file("test", "-e", "f.txt");

	check_file &&           // shell equivalent: test -e f.txt && rm f.txt
	rm + "f.txt";

	dwm &                   // shell equivalent: dwm & st & emacs & echo Starting...
	st &
	emacs &
	echo + "Starting...";

	exec( rm + "log.txt" + "err.txt" );   // shell equivalent: exec rm log.txt err.txt
}