Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Aug 2014 19:16:43 +0200
From:      "Michael Ross" <gmx@ross.cx>
To:        freebsd-questions@freebsd.org, "Peter Ulrich Kruppa" <ulrich@pukruppa.de>
Subject:   Re: sh stdout/stderr redirection problem
Message-ID:  <op.xko3l5f2g7njmm@michael-think>
In-Reply-To: <53EF6979.2080708@pukruppa.de>
References:  <53EF6979.2080708@pukruppa.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 16 Aug 2014 16:23:53 +0200, Peter Ulrich Kruppa  
<ulrich@pukruppa.de> 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


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"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?op.xko3l5f2g7njmm>