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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:57:54+00:00 2026-05-13T23:57:54+00:00

I am trying to create something in Perl that is basically like the Unix

  • 0

I am trying to create something in Perl that is basically like the Unix tee command. I’m trying to read each line of STDIN, run a substitution on it, and print it. (And eventually, also print it to a file.) This works if I’m using console input, but if I try to pipe input to the command it doesn’t do anything. Here’s a simple example:

print "about to loop\n";
while(<STDIN>)
{
  s/2010/2009/;
  print;
}
print "done!\n";

I try to pipe the dir command to it like this:

C:\perltest>dir | mytee.pl
about to loop
done!

Why is it not seeing the piped input? (I’m using Perl 5.10.0 on WinXP, if that is relevant.)

  • 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-13T23:57:54+00:00Added an answer on May 13, 2026 at 11:57 pm

    This is actually a bug in how Windows handles IO redirection. I am looking for the reference right now, but it is that bug that requires you to specify

    dir | perl filter.pl
    

    rather than being able to use

    dir | filter
    

    See Microsoft KB article STDIN/STDOUT Redirection May Not Work If Started from a File Association:

    1. Start Registry Editor.
    2. Locate and then click the following key in the registry:
      HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
    3. On the Edit menu, click Add Value, and then add the following registry value:
      • Value name: InheritConsoleHandles
      • Data type: REG_DWORD
      • Radix: Decimal
      • Value data: 1
    4. Quit Registry Editor.
    C:\Temp> cat filter.pl
    #!/usr/bin/perl
    
    while ( <> ) {
        print "piped: $_";
    }
    C:\Temp> dir | filter
    piped:  Volume in drive C is MAIN
    piped:  Volume Serial Number is XXXX-XXXX
    piped:
    piped:  Directory of C:\Temp>
    piped:
    piped: 2010/03/19  03:48 PM              .
    piped: 2010/03/19  03:48 PM              ..
    piped: 2010/03/19  03:33 PM                32 m.pm
    piped: 2010/03/19  03:48 PM                62 filter.pl
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.