I am trying to verify the existence of SVN tags with a Perl script. So I'm trying to call svn info $url , read the exit code and suppress standard output and standard error streams. However, I try my best to do this (there are probably better ways to ask SVN about the tag, but this is not the point):
my $output = `svn info $url/tags/$tag`;
This suppresses the output by putting it in $output . The exit code is lost.
my $output = `svn info $url/tags/$tag 2>&1`;
This suppresses both STDERR and STDOUT and puts them in $output . The exit code is again lost.
my $exitcode = system("svn", "info", "$url/tags/$tag");
This catches the exit code, but the actual stream of output and errors is displayed to the user.
open( STDERR, q{>}, "/dev/null" ); open my $fh, q{>}, "/dev/null"; select($fh); if (system("svn", "info", "$url/tags/$tag") != 0) { select(STDOUT); print ("Tag doesn't exist!"); do_something_with_exit(); } select(STDOUT); print "Exit code: $exitcode";
This kills STDOUT and STDERR and catches the exit code, but it is ugly because I would have to remember to switch STDOUT back to the original.
So is there a more elegant solution?
perl stdout stderr exit-code
Nikolai Prokoschenko
source share