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 8974961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:46:22+00:00 2026-06-15T18:46:22+00:00

For my upcoming PulseAudio library I want to redirect STDERR and STDOUT to /dev/null

  • 0

For my upcoming PulseAudio library I want to redirect STDERR and STDOUT to /dev/null logically this works,

sub _exec {
    open (*STDERR, '>', '/dev/null');    
    open (*STDOUT, '>', '/dev/null');    
    CORE::system('pacmd', @_ ) or die $?;

However, this still outputs to the term….

sub _exec {
    local ( *STDERR, *STDOUT );
    open (*STDERR, '>', '/dev/null');    
    open (*STDOUT, '>', '/dev/null');    
    CORE::system('pacmd', @_ ) or die $?;

That leaves me with two questions

  1. First and foremost, why am I experiencing the behavior that I’m seeing?
  2. Secondly, is there a more efficient method that doesn’t involve storing the old value and replacing it?
  • 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-06-15T18:46:22+00:00Added an answer on June 15, 2026 at 6:46 pm

    The child writes to fd 1 and 2, yet you didn’t change fd 1 and 2. You just created new Perl variables (something the child knows nothing about) with fd 3 and 4 (something the child doesn’t care about).

    Here’s one way of achieving what you want:

    use IPC::Open3 qw( open3 );
    
    sub _exec {
        open(local *CHILD_STDIN,  '<', '/dev/null') or die $!;
        open(local *CHILD_STDOUT, '>', '/dev/null') or die $!;
        my $pid = open3(
            '<&CHILD_STDIN',
            '>&CHILD_STDOUT',
            undef,  # 2>&1
            'pacmd', @_,
        );
        waitpid($pid, 0);
        die $! if $? == -1;
        die &? if $?;
    }
    

    open3 is pretty low level, but it’s far higher level than doing it yourself*. IPC::Run and IPC::Run3 are even higher level.


    * — It takes care for forking and assigning the handles to the right file descriptors. It handles error checking, including making pre-exec errors in the child appear to be the launch failures they are and not errors from the executed program.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me for the upcoming question, lol. (Im terribly new at this) I have
While performing some upcoming maintenance, I'm going to have to redirect all site traffic
What are the requirements for the upcoming .NET 4 release? Searched around for this
This is for an upcoming project. I have two tables - first one keeps
I'm studying for upcoming interviews and have encountered this question several times (written verbatim)
I have an upcoming deadline on Nov. 1st, 2011, and I want to print
I have an upcoming project coming up in which I want to dedicate several
I get the upcoming error while validating the XML against the schema. Value 'this/is/a/simple/node-path'
I've put together this little loop to display upcoming 4 events from the calendar.
I am trying to retrieve this http://www.vgreleases.com/ReleaseDates/Upcoming.aspx It is a list of upcoming titles.

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.