views:

859

answers:

3

I'm trying to port a Perl script over from Unix to Windows but am having a near impossible time getting it to work due to the unsupported forking pipes in the open function. Here's the code:

sub p4_get_file_content {
    my $filespec = shift;
    return 'Content placeholder!' if ($options{'dry-run'});
    debug("p4_get_file_content: $filespec\n");
    local *P4_OUTPUT;
    local $/ = undef;
    my $pid = open(P4_OUTPUT, "-|");
    die "Fork failed: $!" unless defined $pid;
    if ($pid == 0) { # child
        my $p4 = p4_init();
        my $result = undef;
        $result = $p4->Run('print', $filespec);
        die $p4->Errors() if $p4->ErrorCount();
        if (ref $result eq 'ARRAY') {
            for (my $i = 1; $i < @$result; $i++) {
                print $result->[$i];
            }
        }
        $p4->Disconnect();
        exit 0;
    }
    my $content = <P4_OUTPUT>;
    close(P4_OUTPUT) or die "Close failed: ($?) $!";
    return $content;
}

The error is:

'-' is not recognized as an internal or external command,
operable program or batch file.

Does anyone know how to make this work? Thanks!

Mike

+3  A: 

I know it's not a direct answer to your question, but it looks like you're scripting something on top of Perforce in Perl? If so you might find an existing library does what you want already and save yourself a lot of headaches, or at least give you some sample code to work from.

For example:

EDIT: Now that I know what you're doing I'm guessing you're trying to port p42svn to Windows, or rather make it compatible with Windows at least. See this thread for a discussion of this exact issue. The recommendation (untested) is to try the code samples listed at http://perldoc.perl.org/perlfork.html under "Forking pipe open() not yet implemented" to explicitly create the pipe instead.

Jay
Yup, I'm trying to migrate a Perforce database to Subversion database. However, there's only one known script on the planet that can do this and that script will only run on UNIX which isn't an option for me. I'm trying to port the script over to run on Windows. Before today, I've never touched PERL
Ok, so this must be p42svn then. See my updated answer
Jay
+1  A: 

It's not going to work as-is. You'll need to find another method to accomplish what it's doing. It doesn't look like there's that burning a need for the fork-pipe, but it's hard to tell since I don't know what a p4 is and a lot of your code is being lost to angle bracket interpretation.

chaos
A: 

Gah! These FORKING pipes!

Sheesh!

JDrago