You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Oliver Menge <om...@joe-list.de> on 2006/01/17 07:33:42 UTC
perl backticks do not capture output (post-commit hook)
Hello!
Maybe this is not a real subversion question but I am learning too
many things at the same time. Though it maybe a perl issue I hope to
get some help here. I have a problem writing a post-commit script in
perl on a W2K server (perl as a means to overcome the cmd-limitations
of Windows). However I am neither a windows nor a perl or subversion
expert.
My perl script (post-commit) fails to capture the output of a
backtick-call to svnlook, but only when invoked by subversion. When I
forge the svn call from the command line the scrpt works fine.
I reduced the complexity to make myself clear:
The repository resides in c:/joe/svnrepositories/svn.
Subversion resides in c:/Programme/subversion
!-------------------------------------------------------------------------
! C:\>type c:\joe\svnrepositories\joe\hooks\post-commit.cmd
! c:\perl\bin\perl -Ic:\joe\perlscripts c:\joe\perlscripts\post-commit.pl %1 %2
! C:\>
! --------------------------------------------------------------------------
! C:\>type c:\joe\perlscripts\post-commit.pl
! #!/usr/bin/perl
!
! $reppath = $ARGV[0];
! $revision = $ARGV[1];
!
! #`echo hook output $reppath $revision > c:\\log.txt`;
! #`c:/Programme/subversion/bin/svnlook.exe -r $revision changed $reppath >> c:/log.txt`;
! # exit;
!
! @svnlook_output = `c:/Programme/subversion/bin/svnlook.exe -r $revision changed $reppath`;
! open(HLOG, ">C:/log.txt");
! print HLOG "hook output $reppath $revision\n";
! print HLOG @svnlook_output;
! close(HLOG);
!
! C:\>
--------------------------------------------------------------------------
The script works fine when called from the command prompt:
--------------------------------------------------------------------------
! C:\>perl c:\joe\perlscripts\post-commit.pl /joe/svnrepositories/joe 250
!
! C:\>type c:\log.txt
! hook output /joe/svnrepositories/joe 250
! U trunk/listserv/lists/joe-test/mailtpl/POST_EDITOR
!
! C:\>
--------------------------------------------------------------------------
However when called directly from svn after a commit the STDOUT-output
is not captured:
--------------------------------------------------------------------------
! C:\>type c:\log.txt
! hook output /joe/svnrepositories/joe 254
!
! C:\>
--------------------------------------------------------------------------
When I change post-commit.pl and uncomment the lines that redirect the
output directly to the file c:\log.txt, this file contains everything
what is needed. My conclusion is that the backtick operator genarally
works (svnlook *is* being executed) however perl does not capture the
output in my first variant. But of course I need that output for
parsing...
I'm sure I am missing something here. But what...?
Just in case some version information:
--------------------------------------------------------------------------
! C:\>perl -v
!
! This is perl, version 5.005_03 built for MSWin32-x86-object
! (with 1 registered patch, see perl -V for more detail)
!
...
!
! C:\>
--------------------------------------------------------------------------
and
--------------------------------------------------------------------------
! C:\>svn --version
! svn, Version 1.2.3 (r15833)
! Subversion ist Open Source Software, siehe http://subversion.tigris.org/
! Dieses Proukt enthlt von CollabNet entwickelte Software.
! (http://www.collab.net/)
...
! C:\>
--------------------------------------------------------------------------
Thanks in advance for any hints,
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Re: perl backticks do not capture output (post-commit hook)
Posted by Oliver Menge <om...@joe-list.de>.
Allan,
thanks for bringing me on the right track!
> Oliver Menge wrote:
> > !-------------------------------------------------------------------------
> > ! C:\>type c:\joe\svnrepositories\joe\hooks\post-commit.cmd
> > ! c:\perl\bin\perl -Ic:\joe\perlscripts c:\joe\perlscripts\post-commit.pl %1 %2
> > ! C:\>
> > ! --------------------------------------------------------------------------
Allen Juul wrote:
> it might be the environment is gone in the script.
>
> what happens if you chdir to the executing dir:
>
> # in your bat/cmd file:
> c:
> cd c:\joe\perlscripts
> start c:\perl\bin\perl.exe c:\joe\perlscripts\post-commit.pl %1 %2
Not the working dir but the usage of 'start' (whatever meaning that
has in Windows) makes the difference:
- without 'start' -> cannot capture svnlook output.
- with 'start' -> captures perfectly
Thanks a lot, before I asked the list I had spent many hours on that!
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Re: perl backticks do not capture output (post-commit hook)
Posted by allan juul <al...@muly.dk>.
Oliver Menge wrote:
> Hello!
>
> Maybe this is not a real subversion question but I am learning too
> many things at the same time. Though it maybe a perl issue I hope to
> get some help here. I have a problem writing a post-commit script in
> perl on a W2K server (perl as a means to overcome the cmd-limitations
> of Windows). However I am neither a windows nor a perl or subversion
> expert.
>
> My perl script (post-commit) fails to capture the output of a
> backtick-call to svnlook, but only when invoked by subversion. When I
> forge the svn call from the command line the scrpt works fine.
>
> I reduced the complexity to make myself clear:
>
> The repository resides in c:/joe/svnrepositories/svn.
> Subversion resides in c:/Programme/subversion
>
> !-------------------------------------------------------------------------
> ! C:\>type c:\joe\svnrepositories\joe\hooks\post-commit.cmd
> ! c:\perl\bin\perl -Ic:\joe\perlscripts c:\joe\perlscripts\post-commit.pl %1 %2
> ! C:\>
> ! --------------------------------------------------------------------------
> ! C:\>type c:\joe\perlscripts\post-commit.pl
> ! #!/usr/bin/perl
> !
> ! $reppath = $ARGV[0];
> ! $revision = $ARGV[1];
> !
> ! #`echo hook output $reppath $revision > c:\\log.txt`;
> ! #`c:/Programme/subversion/bin/svnlook.exe -r $revision changed $reppath >> c:/log.txt`;
> ! # exit;
> !
> ! @svnlook_output = `c:/Programme/subversion/bin/svnlook.exe -r $revision changed $reppath`;
> ! open(HLOG, ">C:/log.txt");
> ! print HLOG "hook output $reppath $revision\n";
> ! print HLOG @svnlook_output;
> ! close(HLOG);
> !
> ! C:\>
> --------------------------------------------------------------------------
it might be the environment is gone in the script.
what happens if you chdir to the executing dir:
# in your bat/cmd file:
c:
cd c:\joe\perlscripts
start c:\perl\bin\perl.exe c:\joe\perlscripts\post-commit.pl %1 %2
also you might want to use this form of executing instead of backsticks.
this might be a help when encountering funny characters in filenames
local *SVNLOOK;
open(SVNLOOK, '-|:utf8', $cmd) || die("$!, cmd: $cmd");
my @svnlook_output = <SVNLOOK>;
close SVNLOOK;
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org