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

  • Home
  • SEARCH
  • 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 1898722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:48:07+00:00 2026-05-17T06:48:07+00:00

Using PHP’s proc_open() , I can start a process, read from STDOUT and STDERR

  • 0

Using PHP’s proc_open(), I can start a process, read from STDOUT and STDERR (separately) an arbitrary number of bytes at a time using fread() while the process is running, detect when the process is done using feof() on the STDOUT and STDERR pipes, and then use proc_close() to get the exit code of the process. I’ve done all of this in PHP. It works well, and gives me a lot of control.

Is there a way to do all of these things in Perl? To summarize, I need to be able to do the following:

  • start an external process
  • read STDOUT and STDERR separately
  • read STDOUT and STDERR an arbitrary number of bytes at a time while the process is running (i.e. without having to wait for the process to finish)
  • detect when the process is finished
  • get the exit code of the process

Thanks in advance for your answers.

  • 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-17T06:48:07+00:00Added an answer on May 17, 2026 at 6:48 am

    You could roll your own solution using Perl’s system call interface, but it’s easier to use the built-in module IPC::Open3. As for your list:

    Start an external process:

    use IPC::Open3;
    use IO::Handle;
    use strict;
    
    my $stdout = IO::Handle->new;
    my $stderr = IO::Handle->new;
    my $pid = open3(undef, $stdout, $stderr, 'my-command', 'arg1', 'arg2');
    

    Read STDOUT and STDERR separately, an arbitrary number of bytes at a time:

    my $line = <$stdout>;
    # Or
    sysread $stderr, my $buffer, 1024;
    

    Detect when the process is finished:

    use POSIX qw(sys_wait_h);
    
    waitpid $pid, 0;  # Waits for process to terminate
    waitpid $pid, WNOHANG;  # Checks if the process has terminated
    

    Get the exit code of the process:

    my $status = $?;  # After waitpid indicates the process has exited
    

    Be sure to read the IPC::Open3 documentation; as it warns, it’s easy to get yourself deadlocked when you have separate stdout and stderr pipes, if you’re not careful. If the child process fills either pipe, it will block, and if the parent process reads the other pipe, it will block.

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

Sidebar

Related Questions

I've been using PHP & MySQL for ages and am about to start using
Using PHP, given a URL, how can I determine whether it is an image?
Using PHP I'm attempting to take an HTML string passed from a WYSIWYG editor
Using PHP's system function, how can you pass arguments to a batch file? It
Using PHP and MySQL I'm trying to select unique values from multiple columns in
Using PHP, what's the fastest way to convert a string like this: 123 to
Using PHP and MySQL, I have a forum system I'm trying to build. What
Been using PHP/MySQL for a little while now, and I'm wondering if there are
In using PHP's DOM classes (DOMNode, DOMEElement, etc) I have noticed that they possess
I have been using PHP and JavaScript for building my dad's website. He wants

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.