3

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.

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

3

You placed the pipe on the wrong end of your command. Try this:

my $updatedCmd = "svn diff --summarize $svnOldFull $svnNewFull|";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.