8000 GitHub - kitearuba/pipex: πŸ› οΈ Simulates shell command piping and redirection. Implements Unix behavior using file descriptors and multiple processes β€” cmd1 < infile | cmd2 > outfile.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

πŸ› οΈ Simulates shell command piping and redirection. Implements Unix behavior using file descriptors and multiple processes β€” cmd1 < infile | cmd2 > outfile.

Notifications You must be signed in to change notification settings

kitearuba/pipex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


πŸ› οΈ Pipex - Unix Pipe Handling in C πŸ› οΈ

Pipex C Programming Makefile 42 Network

Welcome to Pipex, a foundational project in the 42 School curriculum designed to deepen understanding of Unix pipe mechanics, process creation, and inter-process communication through the use of C programming. This implementation adheres strictly to the 42 Norm and project specifications, featuring modular code, centralized error handling, and a clean structure to ensure maintainability.


πŸ“‘ Table of Contents

  1. Introduction
  2. Project Structure
  3. Key Features
  4. Technologies Used
  5. Installation
  6. Usage
  7. Error Handling and Exit Codes
  8. Contributing
  9. Ac 8000 knowledgements
  10. Author

πŸ“– Introduction

Pipex emulates Unix shell behavior for piping commands, allowing you to execute:

< infile cmd1 | cmd2 > outfile

The program demonstrates:

  • Process management using fork.
  • Pipe redirection with dup2.
  • File I/O operations with open, close, and system calls.
  • Handling complex edge cases (e.g., missing files, invalid commands).

This project lays a strong foundation for more advanced projects like Minishell and Philosophers.


πŸ“‚ Project Structure

.
β”œβ”€β”€ include/           # Header files
β”‚   └── pipex.h        # Centralized function declarations and macros
β”œβ”€β”€ libft/             # Enhanced Libft with additional utilities
β”‚   β”œβ”€β”€ include/       # Header files for libft
β”‚   └── src/           # Source files for libft
β”œβ”€β”€ src/               # Pipex implementation files
β”‚   β”œβ”€β”€ cmd/           # Command execution logic
β”‚   β”œβ”€β”€ core/          # Core application logic
β”‚   β”œβ”€β”€ error/         # Centralized error handling
β”‚   β”œβ”€β”€ file/          # File and pipe management
β”‚   └── utils/         # Utility functions for memory/resource cleanup
β”œβ”€β”€ Makefile           # Automates compilation
└── README.md          # Documentation (this file)

πŸ”‘ Key Features

Modular Codebase

  • Functions grouped by responsibilities for better organization and reusability:
    • cmd/: Command path resolution and execution (exec_cmd, get_cmd_path).
    • core/: Application entry point (pipex.c).
    • error/: Unified error handling (free_resources_on_error).
    • file/: File and pipe operations (open_files, create_pipe).
    • utils/: Resource cleanup utilities (free_2d_array, free_pipex).

Centralized Error Handling

  • Errors are processed through a single entry point, ensuring proper cleanup and detailed error messages. Exit codes conform to Unix standards:
    • 127: Command not found.
    • 126: Permission denied.
    • 1: Generic error.

Comprehensive Comments

  • Documentation for each function following 42 Norm, making the project beginner-friendly and easy to extend.

πŸ› οΈ Technologies Used

  • C Programming: Core implementation.
  • Libft Library: Extended functionality with ft_printf and utilities.
  • Makefile: For efficient compilation.
  • GCC Compiler: Compilation with strict warnings and memory debugging enabled.

πŸš€ Installation

Step 1: Clone the Repository

git clone https://github.com/kitearuba/pipex.git

Step 2: Navigate to the Project Directory

cd pipex

Step 3: Compile the Project

Run:

make

πŸ’‘ Usage

Basic Example

To emulate:

< infile cmd1 | cmd2 > outfile

Run:

./pipex infile "cmd1" "cmd2" outfile

πŸ›‘ Error Handling and Exit Codes

Exit Codes

  • 127: Command not found or invalid path.
  • 126: Permission denied for the command.
  • 1: Other errors (e.g., failed file open).

Examples

  1. Missing Input File:

    ./pipex nonexistent.txt "ls" "wc" output.txt

    Output:

    pipex: Unable to open input file: No such file or directory
  2. Invalid Command:

    ./pipex infile "invalidcmd" "wc" outfile

    Output:

    pipex: invalidcmd: command not found

🀝 Contributing

Suggestions and improvements are always welcome! Feel free to fork the repository and submit a pull request.


πŸ™Œ Acknowledgements

Special thanks to the 42 Network community for providing a collaborative learning environment and valuable feedback.


πŸ‘¨β€πŸ’» Author


About

πŸ› οΈ Simulates shell command piping and redirection. Implements Unix behavior using file descriptors and multiple processes β€” cmd1 < infile | cmd2 > outfile.

Resources

Stars

Watchers

Forks

Releases

No releases published
37DB

Packages

No packages published
0