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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:56:34+00:00 2026-06-09T12:56:34+00:00

I have a program that is supposed to run a set of other programs

  • 0

I have a program that is supposed to run a set of other programs and collect their output for logging purposes. Everything is working fine as long as there is output to standard out.

That leads me to my two problems:

  1. How can I capture both STDIN and STDERR of another program in one file?

  2. If there is no output at all (or output to STDERR only) the program will get stuck on the line:

    while (<$input>)
    

How can I make the program wait for possible output from another program of indeterminate run time, and still continue if there is no output by the time the program finishes execution.

Here is that section of the code

my $pid = open (my $input, '-|', "$prog $args")
        or push @errors, "A failute has occurred in $prog $args";
if(not @errors){
    while (<$input>){ #POSSIBLE LOCATION FOR HANG UP IF NO PRINTING IS DONE
        if($input =~ /^END\n$/){
            last;
        }
        print $fh $_;
    }
}
else{
    print $fh "An error has occurred with executing \"$prog $args\"";
}

note: $fh is my file handler used to write to my log file, and @errors is used for internally reporting errors in my program.

EDIT:
One problem I experienced with trying the Proc::Reliable route is that it seems to have after effects on STDOUT and STDERR, and I would need to fix those after each call to run. This leads to another problem in my code. I am running in parallel and any change to STDOUT and STDERR effect all of the threads (using Windows at least).

IO::CaptureOutput has the same issue for me, but it tries to correct the STDOUT and STDERR jumbling internally and causes the following error to occur:

Couldn't remove temp file 'C:\Users\SBLAKE~1\AppData\Local\Temp\m8E3pUGfOS' - Permission denied at C:/Perl/site/lib/IO/CaptureOutput.pm line 82
  • 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-09T12:56:35+00:00Added an answer on June 9, 2026 at 12:56 pm

    If you launch from a POSIX-like shell, then the 2>&1 notation sends standard error to the same place as the standard output:

    some-program-to-be-logged 2>&1 | perl logger.pl -o /chosen/log.file
    

    Both standard output and standard error are sent to the standard input of the Perl logging script.

    The input loop in the logger script will hang waiting until there is input to read, or until all the processes with the pipe open for writing close the pipe (typically because they exit).

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

Sidebar

Related Questions

I have a java program that is supposed to run a bat file, and
Ok, so I have a simple c++ program that's supposed to run a couple
I have a requirement such that my program is suppose to run for a
I have a program that is supposed to interact with a web server and
I have a small program that's supposed to sample some value from a device
I have a program for the iPhone that is supposed to be doing intelligent
I have a program that is supposed to send a file to a web
I have a C# Program that is supposed to be multi-OS compatible. It requires
I'm working on a bit of code that is supposed to run an exe
I have a program that is supposed to clear the screen and print my

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.