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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:05:05+00:00 2026-05-15T01:05:05+00:00

I’m writing a System::Wrapper module to abstract away from CORE::system and the qx operator.

  • 0

I’m writing a System::Wrapper module to abstract away from CORE::system and the qx operator. I have a serial method that attempts to connect command1’s output to command2’s input. I’ve made some progress using named pipes, but POSIX::mkfifo is not cross-platform.

Here’s part of what I have so far (the run method at the bottom basically calls system):

package main;

my $obj1 = System::Wrapper->new(
    interpreter => 'perl',
    arguments   => [-pe => q{''}],
    input       => ['input.txt'],
    description => 'Concatenate input.txt to STDOUT',
);

my $obj2 = System::Wrapper->new(
    interpreter => 'perl',
    arguments   => [-pe => q{'$_ = reverse $_}'}],
    description => 'Reverse lines of input input',
    output      => { '>' => 'output' },
);

$obj1->serial( $obj2 );


package System::Wrapper;

#...

sub serial {
    my ($self, @commands) = @_;

    eval {
        require POSIX; POSIX->import();
        require threads;
    };

    my $tmp_dir = File::Spec->tmpdir();

    my $last = $self;

    my @threads;

    push @commands, $self;

    for my $command (@commands) {

        croak sprintf
        "%s::serial: type of args to serial must be '%s', not '%s'",
        ref $self, ref $self, ref $command || $command
        unless ref $command eq ref $self;

        my $named_pipe = File::Spec->catfile( $tmp_dir, int \$command );

        POSIX::mkfifo( $named_pipe, 0777 )
          or croak sprintf
          "%s::serial: couldn't create named pipe %s: %s",
          ref $self, $named_pipe, $!;

        $last->output( { '>' => $named_pipe } );
        $command->input( $named_pipe );

        push @threads, threads->new( sub{ $last->run } );
        $last = $command;
    }

    $_->join for @threads;
}

#...

My specific questions:

  1. Is there an alternative to POSIX::mkfifo that is cross-platform? Win32 named pipes don’t work, as you can’t open those as regular files, neither do sockets, for the same reasons.

    2. The above doesn’t quite work; the two threads get spawned correctly, but nothing flows across the pipe. I suppose that might have something to do with pipe deadlocking or output buffering. What throws me off is that when I run those two commands in the actual shell, everything works as expected.

Point 2 is solved; a -p fifo file test was not testing the correct file.

  • 1 1 Answer
  • 1 View
  • 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-15T01:05:06+00:00Added an answer on May 15, 2026 at 1:05 am

    Out of interest, why do you need a FIFO? Couldn’t you just set up a regular pipe (e.g. with pipe?) And why use threads when you can use the much more strongly supported fork?

    In fact, you could instead use a CPAN module to do most of your work for you. IPC::Run for example:

    use IPC::Run qw(run);
    run ['perl', '-pe', ''], '<', 'input.txt', '|', ['perl', '-pe', '$_ = reverse $_}'], '>', 'output';
    

    …should work as you expect, on Linux or Windows.

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

Sidebar

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.