Jia
Comments are below
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
···
On Tue, Jul 13, 2010 at 6:37 AM, Jia Hu <hujia06@gmail.com> wrote: