From owner-freebsd-questions@FreeBSD.ORG Sun Aug 17 07:53:39 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 81FF7366 for ; Sun, 17 Aug 2014 07:53:39 +0000 (UTC) Received: from pukruppa.de (pd95cabe3.dip0.t-ipconnect.de [217.92.171.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "pukruppa.de", Issuer "pukruppa.de" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 105A32635 for ; Sun, 17 Aug 2014 07:53:38 +0000 (UTC) Received: from pukruppa.de (localhost [127.0.0.1]) by pukruppa.de (8.14.9/8.14.9) with ESMTP id s7H7raBW058226 for ; Sun, 17 Aug 2014 09:53:36 +0200 (CEST) (envelope-from ulrich@pukruppa.de) Message-ID: <53F05F80.7070507@pukruppa.de> Date: Sun, 17 Aug 2014 09:53:36 +0200 From: Peter Ulrich Kruppa User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Re: sh stdout/stderr redirection problem References: <53EF6979.2080708@pukruppa.de> In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Aug 2014 07:53:39 -0000 On 16.08.2014 19:16, Michael Ross wrote: > On Sat, 16 Aug 2014 16:23:53 +0200, Peter Ulrich Kruppa > wrote: > >> Hi, >> >> I have got a python3.4 script which I can start from an rc.d script as a >> daemon this way: >> >> daemon -p /var/run/my.pid /path/to/python3.4 /path/to/myscript.py >> >> >> /path/to/python3.4 /path/to/myscript.py produces interesting messages on >> stdout and stderr, so I would like to collect them in /var/log/my.log . >> I have tried all kinds of combinations of >>'s and 2>&1's but either I >> catch daemon's output which is nothing or the script won't start anymore. >> >> Any ideas? - Thanks for your help >> >> Peter > > You could do the redirection in your python script: > > http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python > > > Basically, > > import sys > f=open('logfile','w') > > def redirect(msg): > f.write(msg) > > sys.stdout=redirect > sys.stderr=redirect Thanks for your idea - using python's redirection should be the "nice" way to solve my problem, but I have to admit I couldn't get that working, yet - I end up with an empty logfile. For now I am happy with Polytropon's script solution, but I will put your approach on my ToDo list. Greetings Peter > > > Michael > > >> _______________________________________________ >> freebsd-questions@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-questions >> To unsubscribe, send any mail to >> "freebsd-questions-unsubscribe@freebsd.org" > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" >