Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3307096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:21:58+00:00 2026-05-17T21:21:58+00:00

From this perldoc page , To capture a command’s STDERR and STDOUT together: $output

  • 0

From this perldoc page,

  1. To capture a command’s STDERR and STDOUT together:

    $output = `cmd 2>&1`;
  2. To capture a command’s STDOUT but discard its STDERR:

    $output = `cmd 2>/dev/null`;
  3. To capture a command’s STDERR but discard its STDOUT (ordering is important here):

    $output = `cmd 2>&1 1>/dev/null`;
  4. To exchange a command’s STDOUT and STDERR in order to capture the STDERR but leave its STDOUT to come out the old STDERR:

    $output = `cmd 3>&1 1>&2 2>&3 3>&-`;

I do not understand how 3 and 4 work, and I am not too sure what I understand about 1 and 2 is right. Below is what I understand. Please correct me where I am wrong.

I know that 0, 1 and 2 symbolize STDIN, STDOUT and STDERR.

  1. redirect 2 to 1, so that both of them use the same stream now (& escaped 1 making sure that STDERR does not get redirected to a file named 1 instead)

  2. redirect 2 (STDERR) to null stream, so that it gets discarded

  3. I do not understand this one. Shouldn’t it be just

    $output = `cmd 1>/dev/null`;

    Also, if the aim is to get the STDERR messages at STDOUT, won’t 1>/dev/null redirect everything to /dev/null?

  4. What is happening here? What is stream 3? Is it like a temporary variable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:21:58+00:00Added an answer on May 17, 2026 at 9:21 pm

    Really, none of this is Perl — all of this is handled by the shell that you’re invoking by using the backticks operator. So your best reading is man sh, or the Shell chapter of the Unix standard.

    In short, though, for #4:

    • 3>&1: Open FD 3 to point to where stdout currently points.
    • 1>&2: Reopen stdout to point to where stderr currently points.
    • 2>&3: Reopen stderr to point to where FD 3 currently points, which is where stdout pointed before the previous step was completed. Now stdout and stderr have been succesfully swapped.
    • 3>&-: Close FD 3 because it’s not needed anymore.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended
From this article , /^1?$|^(11+?)\1+$/ checks whether a number(its value in unary) is prime
I copied this example from perldoc -f sort . I added the @old array
From this XHTML source: <div class = page> <h1>UNIQUE NAME</h1> <table> <tbody> <tr> <td>DATA
From this article I see I can use msbuild to apply configuration transformations but
From this guide , I have successfully run the sample exercise. But on running
From perldoc -f bless : bless REF,CLASSNAME This function tells the thingy referenced by
From this page I have come to understand that: font.main=4 will give me a
From the "our" perldoc : our has the same scoping rules as my, but
From this morning, I am facing weird issues with Rails devise. Following is output

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.