Member-only story

Dennis O'Keeffe
3 min readJul 28, 2020

--

Heading image

This short post is a recount of an exploration into redirection in the C language.

As always, let’s go to our friend Wikipedia to set the definition for us:

In computing, redirection is a form of interprocess communication, and is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.

In Unix-like operating systems, programs do redirection with the dup2(2) system call, or its less-flexible but higher-level stdio analogues, freopen(3) and popen(3).

Basic redirection can use < to redirect input and > to redirect output.

For example, we can use the redirect output operator to redirect the output from echo "Hello!" into a file example.txt.

As mentioned by our pal Wikipedia, we can use the dup2 system call in C to manage a similar thing!

A simple example

In our first example, we are going to write a simple example of two variables that open a foobar.txt that iterates character by character.

--

--

Dennis O'Keeffe
Dennis O'Keeffe

No responses yet