FlowControl is a C++ framework designed for interpreting and executing sequences of commands described in .flow
files. This framework simulates shell command execution, including complex piping, redirection, and concatenation, tailored for Unix-like systems. It's an ideal tool for automating and testing command line operations, making it highly useful for developers and system administrators.
- Command Execution: Directly execute Unix commands through structured scripts.
- Piping and Redirections: Supports complex piping (
|
) and redirections (>
,2>&1
). - Concatenations: Execute commands in sequence using concatenation (
;
). - File Output Handling: Direct command outputs to files for logging and further processing.
- Error Handling: Advanced error redirection and handling for robust script testing.
- Automated Testing: Includes a Python script for automated testing against expected outputs.
Ensure you have GCC (supporting C++11 or later) and Python 3.x installed. Clone the repository and compile the source:
git clone https://yourrepositorylink.com/FlowControl.git
cd FlowControl
g++ -std=c++11 flow.cpp -o flow
.flow
files dictate the operations within the framework. Here’s how to structure these files:
Defines a single command operation.
node=ls_node
command=ls -l
Directs the output of one command to another.
node=echo_node
command=echo "Hello World"
node=wc_node
command=wc -w
pipe=echo_to_wc
from=echo_node
to=wc_node
Executes multiple commands in sequence.
node=date_node
command=date
node=whoami_node
command=whoami
concatenate=system_info
parts=2
part_0=date_node
part_1=whoami_node
Redirects error output to another command.
node=mkdir_attempt
command=mkdir existing_dir
stderr=stdout_to_stderr_for_mkdir
from=mkdir_attempt
pipe=catch_errors
from=stdout_to_stderr_for_mkdir
to=word_count_node
Captures the output of a command and writes it to a file.
node=list_files
command=ls
file=output_file
name=output.txt
pipe=process_pipe
from=list_files
to=output_file
Run python3 run.py
to test all .flow
files in the files
directory. This script compiles the program, runs tests, and saves results to TestResult_{DateTime}.txt
.
- Case 0: A single command node.
- Case 1: Command output redirection to a file.
- Case 2: Piping commands.
- Case 3: Concatenating commands.
- Case 4: Error handling.
- Case 5: File input/output handling.
- Case 6: Complex command sequences.
- Download and extract this repository.
- Run
python3 run.py
- Open
TestResult_{current_time}.txt
for more information.
- 0: just one node in any
.flow
file - 1:
ls | wc
// normal pipe - 2:
ls -l | wc
// if-
arguments can be handled properly - 3:
ls -l | ls
// if pipe can be used for a "to" argument that doesn't take inputs - 4:
echo foo | cat
// no quotes for argument - 5:
echo 'foo' | cat
// single quotes - 6:
echo "foo" | cat
// double quotes - 7:
echo 'f o o' | cat
// quotes with space - 8:
ls ; pwd
// normal concat - 9:
ls; ls ; ls -a
// concat with more than 2 parts and also arguments - 10:
echo foo1 ; echo 'foo2' ; echo "foo3" ; echo 'f o o 4'
// no quotes; double; single; spaces - 11:
ls | wc ; pwd
// mix - 12:
( cat foo.txt ; cat foo.txt | sed s/o/u/g ) | wc
// complicated mix - 13:
( seq 1 5 | awk '{print $1*$1}'; seq 1 5 | awk '{print $1*2}'; seq 1 5 | awk '{print $1+5}' ) | sort -n | uniq
// extra credit - chatgpt - complicated with quotes, arguments, everything - 14:
mkdir a 2>&1
// b would not exist in the directory (calling stderr as action directly) - 15:
mldir a 2>&1 | wc
// calling non-stderr as action - 16:
ls > output.txt
- 17:
cat output.txt | wc