# Redirecting Standard Output in C With the dup2() Function

DevFeed: [Redirecting Standard Output in C With the dup2() Function](<https://devfeed.tech/articles/redirecting-standard-output-in-c-with-the-dup2-function-4519.md>)

Original publisher: [Read original article](<https://feeds.feedblitz.com/~/920203664/0/baeldung/linux~Redirecting-Standard-Output-in-C-With-the-dup-Function>)

Author: Marcin Buczkowski

Published: 2025-06-14T07:02:25Z

Content type: tutorial

Language: en

Sources: [Baeldung - Linux](<https://devfeed.tech/sources/baeldung-linux.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [Redirection](<https://devfeed.tech/topics/redirection.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [Streams](<https://devfeed.tech/topics/streams.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [linux](<https://devfeed.tech/tags/linux.md>), [processes](<https://devfeed.tech/tags/processes.md>), [processes-gcc-redirection-streams](<https://devfeed.tech/tags/processes-gcc-redirection-streams.md>), [redirection](<https://devfeed.tech/tags/redirection.md>), [streams](<https://devfeed.tech/tags/streams.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>)

## AI overview

This tutorial explains how standard input and output redirection works in Linux and how to implement it in C. It introduces file descriptors and standard streams, then shows how dup2() duplicates a descriptor so program output can be redirected to a file without changing the code that writes to STDOUT.

## Source excerpt

Learn how redirection works and the way the dup2() function achieves it in C. The post Redirecting Standard Output in C With the dup2() Function first appeared on Baeldung on Linux. Related Stories How to Find the SCHED_RR Scheduling Policy's Time Slice How Can I Swap Colors With GIMP? How to Identify the Package Manager of a Linux System