You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by David Weintraub <qa...@gmail.com> on 2010/03/10 13:30:03 UTC

STDOUT and Hook Scripts

I know that when you run a hook, the STDOUT is not returned to the
user, and STDERR is only returned if that hook returns a non-zero exit
code.

However, I'm writing a post-commit hook, and I'd like to know if it is
possible to pipe STDOUT to another process as part of the hook script.
For example, in a post-commit hook, I have a Perl script that collects
watch information, and I'd like to pipe the output of that script to
another script that will do the actual notification. Can I do the
following in my post-commit script:

watch-file.pl | notify.pl

Is that possible?

-- 
David Weintraub
qazwart@gmail.com

Re: STDOUT and Hook Scripts

Posted by Les Mikesell <le...@gmail.com>.
On 3/11/2010 12:56 PM, Stein Somers wrote:
> The post-commit hook starts a single process, and eats its STDOUT.
>
> But you can make that single process into whatever you want. If you hook
> script is for instance:
>
> #!/bin/sh
> perl watch-file.pl | perl notify.pl
>
> then your hook consists of a shell process and two perl processors
> working together. SVN doesn't know anything about the STDOUT produced by
> watch-file.pl. It still eats the STDOUT that notify.pl produces -
> someone has to. The commit is finished when notify.pl is done (more or
> less).

Likewise, perl is just as good as the shell at starting programs on 
pipes and manipulating file descriptors.  One program could read from or 
write to a pipe within your perl code.

-- 
   Les Mikesell
    lesmikesell@gmail.com

Re: STDOUT and Hook Scripts

Posted by Stein Somers <ss...@opnet.com>.
The post-commit hook starts a single process, and eats its STDOUT.

But you can make that single process into whatever you want. If you hook 
script is for instance:

#!/bin/sh
perl watch-file.pl | perl notify.pl

then your hook consists of a shell process and two perl processors 
working together. SVN doesn't know anything about the STDOUT produced by 
watch-file.pl. It still eats the STDOUT that notify.pl produces - 
someone has to. The commit is finished when notify.pl is done (more or 
less).

--
Stein

Re: STDOUT and Hook Scripts

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Mar 10, 2010, at 18:35, David Weintraub wrote:

> On Wed, Mar 10, 2010 at 1:31 PM, Ted Stern wrote:
>> What about this basic shell manipulation?
>> 
>> #!/bin/sh
>> 
>> exec 1>&2    # combine stdout with stderr
>> 
>> # do stuff that generates stdout
>> 
>> if [ <condition> ] ; then
>>   exit 1       # return non-zero exit every time there's stdout
>> fi
> 
> I know that hooks don't return STDOUT to the user, but does
> Subversion's hooks eat STDOUT, or can I pass it on to the next
> program. That's what I want to know.

As far as I know, you should be able to pass STDOUT anywhere you want to, like you would in any other script. Have you tried it?


Re: STDOUT and Hook Scripts

Posted by David Weintraub <qa...@gmail.com>.
On Wed, Mar 10, 2010 at 1:31 PM, Ted Stern <do...@gmail.com> wrote:
> What about this basic shell manipulation?
>
> #!/bin/sh
>
> exec 1>&2    # combine stdout with stderr
>
> # do stuff that generates stdout
>
> if [ <condition> ] ; then
>   exit 1       # return non-zero exit every time there's stdout
> fi

I know that hooks don't return STDOUT to the user, but does
Subversion's hooks eat STDOUT, or can I pass it on to the next
program. That's what I want to know.

What you recommend would send STDOUT to the user by sending STDOUT to
STDERR and purposefully failing the script. That's not what I want.

What I want to do is have a script that builds a list of notification
and then passes that along to another program to actually do the
notifications. This way, I can allow the user to choose the method of
sending notifications.

However, I'm taking a slightly different task by simply having
multiple notification subroutines in my script and allowing the user
to select the one they want.

-- 
David Weintraub
qazwart@gmail.com

Re: STDOUT and Hook Scripts

Posted by Ted Stern <do...@gmail.com>.
On 10 Mar 2010 05:30:03 -0800, David Weintraub wrote:
>
> I know that when you run a hook, the STDOUT is not returned to the
> user, and STDERR is only returned if that hook returns a non-zero exit
> code.
>
> However, I'm writing a post-commit hook, and I'd like to know if it is
> possible to pipe STDOUT to another process as part of the hook script.
> For example, in a post-commit hook, I have a Perl script that collects
> watch information, and I'd like to pipe the output of that script to
> another script that will do the actual notification. Can I do the
> following in my post-commit script:
>
> watch-file.pl | notify.pl
>
> Is that possible?

What about this basic shell manipulation?

#!/bin/sh

exec 1>&2    # combine stdout with stderr

# do stuff that generates stdout

if [ <condition> ] ; then
   exit 1       # return non-zero exit every time there's stdout
fi

Ted
-- 
 Frango ut patefaciam -- I break so that I may reveal