Reputation: 5818
I'm attempting to pass perl variables into a system command and then capture the output for later usage, here's my current code:
my $updatedCmd = "|svn diff --summarize $svnOldFull $svnNewFull";
my $updatedUrls = '';
open UPDATES, $updatedCmd or die "Can't get updates";
while(<UPDATES>) {
print $_;
}
print "THIS_SHOULD_OUTPUT_AT_THE_END\n";
The problem with this is that I get the output:
THIS_SHOULD_OUTPUT_AT_THE_END
A /test
A /test2
A /deployment.txt
I would like to be able to capture all of the command output before allowing my perl script to go any further however.
Upvotes: 3
Views: 364
Reputation: 492
More modern way to do this is the following:
my @cmd = qw(svn diff --summarize), $svnOldFull, $svnNewFull;
open my $pipe, '-|', @cmd or die "oops: $!";
while (<$pipe>) { ... }
Advantages
no globals
open mode separated from file/command
command as array, so there is no need in shell quoting
Upvotes: 5
Reputation: 6331
You placed the pipe on the wrong end of your command. Try this:
my $updatedCmd = "svn diff --summarize $svnOldFull $svnNewFull|";
Upvotes: 3