[Radiance-general] Re: python

Jia Hu hujia06 at gmail.com
Tue Jul 13 08:56:29 PDT 2010


Thank you very much. It works now.  A very small error in your code is that
using "cmd" instead of cmd.split(), and
using stdout = subprocess.PIPE.

Thank you,
Jia

On Tue, Jul 13, 2010 at 4:58 AM, Thomas Bleicher
<tbleicher at googlemail.com>wrote:

> Jia
>
> Comments are below
>
> On Tue, Jul 13, 2010 at 6:37 AM, Jia Hu <hujia06 at gmail.com> wrote:
> > Hello:
> >
> > I  made a simplified python code as bellow.
> >
> > #!/usr/bin/python
> > import subprocess
> > fileHandle = open ('final.txt', 'w')
> > fileHandle.write ('%s %s %s \n' % (12,25,89))
> > fileHandle.close()
> > # valueIll = open ('final.txt', 'a')
> > creBlinds = subprocess.Popen("genblinds %s %s %d %d %d %d %d \
> >           | xform -rz -90 -t 2 2 2 >> final.txt " % ('white', 'VBlinds',
> \
> >           0.03, 2, 3, 15, 30), shell=True)
> > fileHandle .close()
> > fileHandle = open ('final.txt', 'a')
> > fileHandle.write ('%s %s %s \n' % (52,86,506))
> > fileHandle.close()
> >
> > What I expect is the text generated by "Gneblinds" are located between
> '12
> > 25 89" and "52 86 506". But I find the text in the second line is (52 86
> > 506) and the following text is generated by "genblinds". Could someone
> give
> > me some advice  to fix this problem?
>
> You have two processes accessing the same file in a very short time.
> Due to some caching that's controlled by the OS you can't guarantee
> that the access happens in the right order. The best way to solve this
> is to use Python to do all the writing:
>
> #!/usr/bin/python
> import subprocess
> fileHandle = open ('final.txt', 'w')
> fileHandle.write ("%s %s %s \n" % (12,25,89))
>
> ## create gensky command
> cmd = "genblinds %s %s %d %d %d %d %d | xform -rz -90 -t 2 2 2 " %
> ('white', 'VBlinds', 0.03, 2, 3, 15, 30)
>
> ## execute in subprocess and read output of gensky command
> output = subprocess.Popen(cmd.split(), stdout=PIPE,
> shell=True).communicate()[0]



>
> ## now write to file
> fileHandle.write(output + "\n")
>
> fileHandle.write ('%s %s %s \n' % (52,86,506))
> fileHandle.close()
>
>
> This is untested. The pipe to xform might mess things up here but I
> hope it works.
>
> Regards,
> Thomas
>
> _______________________________________________
> Radiance-general mailing list
> Radiance-general at radiance-online.org
> http://www.radiance-online.org/mailman/listinfo/radiance-general
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://radiance-online.org/pipermail/radiance-general/attachments/20100713/108dd509/attachment.html


More information about the Radiance-general mailing list