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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:55:12+00:00 2026-06-19T03:55:12+00:00

I know I can do the following: open(STDOUT, |-, cmd); Which presumably results in

  • 0

I know I can do the following:

open(STDOUT, "|-", "cmd");

Which presumably results in the following:

  1. fork();
  2. exec("cmd");
  3. Link STDOUT of original process to STDIN of new process.

What I’d like to do is step 2 above, i.e. don’t do the exec(). Just have two copies of the current process continuing, the STDIN of the child linked to the STDOUT of the parent.

Which would then allow me to continue on like this:

if (! $pid)
{
  # Handle data in child here
  open OUTFILE1 $file1;
  open OUTFILE2 $file2;
  my $i = 0;
  while (<>)
  {
    print (i % 2 ? OUTFILE1 : OUTFILE2) "Line $i: $_";
    ++$i;
  }
  exit;
}
else
{
  # Continue parent here
  print STDOUT "Hello World from print()";
  system("echo Hello World from system()");
}

The above code should add a line number to the output and write this data alternatively line by line to different files (I know it’s a bit silly, but it’s just an example).

Is there a way or a library that does this? I considered perltie but it didn’t seem to handle results from system(), hence I believe I need a separate process to actually pipe STDOUT to.

  • 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-19T03:55:13+00:00Added an answer on June 19, 2026 at 3:55 am

    IIRC, you simply want

    open(STDOUT, "|-", "-");
    

    but open3 also only takes one line, has better error reporting, and would allow you to capture STDERR as well.

    use IPC::Open3 qw( open3 );
    use POSIX      qw( _exit );
    
    sub child {
       print("Hello World from print()\n");
       system("echo", "Hello World from system()");
    }
    
    my $pid = open3(
       '<&STDIN',
       \local *CHILD_STDOUT,
       '>&STDERR',
       '-',
    );
    
    if (!$pid) {
       if (eval { child(); 1 }) {
          _exit(0);
       } else {
          print(STDERR $@);
          _exit($! || ($? >> 8) || 255);
       }
    }
    
    while (<CHILD_STDOUT>) {
       ...
    }
    
    waitpid($pid, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can open Windows Calculator with the following code : System.Diagnostics.Process.Start(calc); But
we are using framework 3.5 please let me know how can I achieve following
I know you can clear options by doing the following: dropDownList.options.length = 0; Is
I would like to know if I can use the following JQuery function on
I know the following function can be used to do some pre-save processing. But,
I wanted to know if anybody can explain me the following piece of Javascript
How can I convert the following array: (Assume I don't know how many depth
I can't make the following work. I know it's because of the PHP function
Why can I not do something like the following when I know that the
I know I can do this, ------ open(F,>,\$var); print F something cool; close(F); print

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.