I asked a programmer at work this morning, he doesn't use Python but he did 
come up with this.


import sys, os

 class Tee:

def __init__(self, filename):

log = open(filename, "w")

self.prevfd = os.dup(sys.__stdout__.fileno())

os.dup2(log.fileno(), sys.__stdout__.fileno())

self.prev = sys.__stdout__

sys.__stdout__ = os.fdopen(self.prevfd, "w")

def __exit__(self):

restore()

def restore():

os.dup2(self.prevfd, self.prev.fileno())

sys.__stdout__ = self.prev

 
# begin redirect logging to file

  tee = Tee("c:\\log.txt")


So at the moment it does what I'm after but it completely redirects the 
output window and now there isn't any output in the console, I don't know 
python well enough at the moment to take it further.

Is there a way to keep both? 


Thanks guys,






On Tuesday, March 6, 2012 11:50:09 AM UTC+11, Justin Israel wrote:
>
> The code I suggested earlier will work for software renders, and, for 
> anything that maya batch reports back to maya's script editor. Maya batch 
> does write to a log file which you could tail, and get your output from 
> there. I'm not sure where it lives on windows, but on OSX it lives in the 
> user home directory here:  ~/Library/Logs/Maya/mayaRender.log
>
> Specifically on windows, if you have the output window showing this info, 
> its being populated by the subprocess of Maya Batch. So, really the logfile 
> is your best approach I think.
>
>
>
> On Mon, Mar 5, 2012 at 4:04 PM, Chad Dombrova <[email protected]> wrote:
>
>> if you're talking about the Output Window that comes with Maya on 
>> Windows, then that is stdout and stderr, which are two special 
>> files/streams that any application can write to.  On linux or osx, when you 
>> start an application you can pipe its output to a file or another 
>> application.  I don't know about windows, but i'm sure there is something 
>> similar.
>>
>> Typically renderers will allow you to specify a file for render logs.  If 
>> it's MR, then there is probably some magic, undocumented environment 
>> variable that does it.
>>
>> why is this forum so slow to update? I posted a topic on Friday and I 
>>> don't see it till Tuesday morning
>>
>>
>> first time posters are moderated.  your moderator did not check his email 
>> over the weekend ;)  if this was not your first time posting, perhaps you 
>> used a different email address.
>>  
>>
>>> and then i replied to this a few hours ago and it doesn't appear....is 
>>> it just me?
>>
>>
>> don't know about the delay in the reply, but in case it helps clear 
>> anything up, by default you won't receive your own responses by email.
>>
>>
>> -chad
>>
>>
>>
>>  -- 
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings: 
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>
On Tuesday, March 6, 2012 11:50:09 AM UTC+11, Justin Israel wrote:
>
> The code I suggested earlier will work for software renders, and, for 
> anything that maya batch reports back to maya's script editor. Maya batch 
> does write to a log file which you could tail, and get your output from 
> there. I'm not sure where it lives on windows, but on OSX it lives in the 
> user home directory here:  ~/Library/Logs/Maya/mayaRender.log
>
> Specifically on windows, if you have the output window showing this info, 
> its being populated by the subprocess of Maya Batch. So, really the logfile 
> is your best approach I think.
>
>
>
> On Mon, Mar 5, 2012 at 4:04 PM, Chad Dombrova <[email protected]> wrote:
>
>> if you're talking about the Output Window that comes with Maya on 
>> Windows, then that is stdout and stderr, which are two special 
>> files/streams that any application can write to.  On linux or osx, when you 
>> start an application you can pipe its output to a file or another 
>> application.  I don't know about windows, but i'm sure there is something 
>> similar.
>>
>> Typically renderers will allow you to specify a file for render logs.  If 
>> it's MR, then there is probably some magic, undocumented environment 
>> variable that does it.
>>
>> why is this forum so slow to update? I posted a topic on Friday and I 
>>> don't see it till Tuesday morning
>>
>>
>> first time posters are moderated.  your moderator did not check his email 
>> over the weekend ;)  if this was not your first time posting, perhaps you 
>> used a different email address.
>>  
>>
>>> and then i replied to this a few hours ago and it doesn't appear....is 
>>> it just me?
>>
>>
>> don't know about the delay in the reply, but in case it helps clear 
>> anything up, by default you won't receive your own responses by email.
>>
>>
>> -chad
>>
>>
>>
>>  -- 
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings: 
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>
On Tuesday, March 6, 2012 11:50:09 AM UTC+11, Justin Israel wrote:
>
> The code I suggested earlier will work for software renders, and, for 
> anything that maya batch reports back to maya's script editor. Maya batch 
> does write to a log file which you could tail, and get your output from 
> there. I'm not sure where it lives on windows, but on OSX it lives in the 
> user home directory here:  ~/Library/Logs/Maya/mayaRender.log
>
> Specifically on windows, if you have the output window showing this info, 
> its being populated by the subprocess of Maya Batch. So, really the logfile 
> is your best approach I think.
>
>
>
> On Mon, Mar 5, 2012 at 4:04 PM, Chad Dombrova <[email protected]> wrote:
>
>> if you're talking about the Output Window that comes with Maya on 
>> Windows, then that is stdout and stderr, which are two special 
>> files/streams that any application can write to.  On linux or osx, when you 
>> start an application you can pipe its output to a file or another 
>> application.  I don't know about windows, but i'm sure there is something 
>> similar.
>>
>> Typically renderers will allow you to specify a file for render logs.  If 
>> it's MR, then there is probably some magic, undocumented environment 
>> variable that does it.
>>
>> why is this forum so slow to update? I posted a topic on Friday and I 
>>> don't see it till Tuesday morning
>>
>>
>> first time posters are moderated.  your moderator did not check his email 
>> over the weekend ;)  if this was not your first time posting, perhaps you 
>> used a different email address.
>>  
>>
>>> and then i replied to this a few hours ago and it doesn't appear....is 
>>> it just me?
>>
>>
>> don't know about the delay in the reply, but in case it helps clear 
>> anything up, by default you won't receive your own responses by email.
>>
>>
>> -chad
>>
>>
>>
>>  -- 
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings: 
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>
On Tuesday, March 6, 2012 11:50:09 AM UTC+11, Justin Israel wrote:
>
> The code I suggested earlier will work for software renders, and, for 
> anything that maya batch reports back to maya's script editor. Maya batch 
> does write to a log file which you could tail, and get your output from 
> there. I'm not sure where it lives on windows, but on OSX it lives in the 
> user home directory here:  ~/Library/Logs/Maya/mayaRender.log
>
> Specifically on windows, if you have the output window showing this info, 
> its being populated by the subprocess of Maya Batch. So, really the logfile 
> is your best approach I think.
>
>
>
> On Mon, Mar 5, 2012 at 4:04 PM, Chad Dombrova <[email protected]> wrote:
>
>> if you're talking about the Output Window that comes with Maya on 
>> Windows, then that is stdout and stderr, which are two special 
>> files/streams that any application can write to.  On linux or osx, when you 
>> start an application you can pipe its output to a file or another 
>> application.  I don't know about windows, but i'm sure there is something 
>> similar.
>>
>> Typically renderers will allow you to specify a file for render logs.  If 
>> it's MR, then there is probably some magic, undocumented environment 
>> variable that does it.
>>
>> why is this forum so slow to update? I posted a topic on Friday and I 
>>> don't see it till Tuesday morning
>>
>>
>> first time posters are moderated.  your moderator did not check his email 
>> over the weekend ;)  if this was not your first time posting, perhaps you 
>> used a different email address.
>>  
>>
>>> and then i replied to this a few hours ago and it doesn't appear....is 
>>> it just me?
>>
>>
>> don't know about the delay in the reply, but in case it helps clear 
>> anything up, by default you won't receive your own responses by email.
>>
>>
>> -chad
>>
>>
>>
>>  -- 
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings: 
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>
On Tuesday, March 6, 2012 11:50:09 AM UTC+11, Justin Israel wrote:
>
> The code I suggested earlier will work for software renders, and, for 
> anything that maya batch reports back to maya's script editor. Maya batch 
> does write to a log file which you could tail, and get your output from 
> there. I'm not sure where it lives on windows, but on OSX it lives in the 
> user home directory here:  ~/Library/Logs/Maya/mayaRender.log
>
> Specifically on windows, if you have the output window showing this info, 
> its being populated by the subprocess of Maya Batch. So, really the logfile 
> is your best approach I think.
>
>
>
> On Mon, Mar 5, 2012 at 4:04 PM, Chad Dombrova <[email protected]> wrote:
>
>> if you're talking about the Output Window that comes with Maya on 
>> Windows, then that is stdout and stderr, which are two special 
>> files/streams that any application can write to.  On linux or osx, when you 
>> start an application you can pipe its output to a file or another 
>> application.  I don't know about windows, but i'm sure there is something 
>> similar.
>>
>> Typically renderers will allow you to specify a file for render logs.  If 
>> it's MR, then there is probably some magic, undocumented environment 
>> variable that does it.
>>
>> why is this forum so slow to update? I posted a topic on Friday and I 
>>> don't see it till Tuesday morning
>>
>>
>> first time posters are moderated.  your moderator did not check his email 
>> over the weekend ;)  if this was not your first time posting, perhaps you 
>> used a different email address.
>>  
>>
>>> and then i replied to this a few hours ago and it doesn't appear....is 
>>> it just me?
>>
>>
>> don't know about the delay in the reply, but in case it helps clear 
>> anything up, by default you won't receive your own responses by email.
>>
>>
>> -chad
>>
>>
>>
>>  -- 
>> view archives: http://groups.google.com/group/python_inside_maya
>> change your subscription settings: 
>> http://groups.google.com/group/python_inside_maya/subscribe
>>
>
>

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to