stdout.readline() works in Python but not in Blender

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Sat Oct 06, 2012 9:37 am

stdout.readline() works in Python but not in Blender

Post by heskn » Sat Oct 06, 2012 10:00 am

import subprocess

NvTriStripPath = "C:/NvTriStripper-cli.exe"
vert_indices = [ 0, 1, 2, 1, 3, 2 ]

# Stripifying mesh
NvTriStrip = subprocess.Popen([NvTriStripPath],
stdin = subprocess.PIPE,
stdout = subprocess.PIPE)

for vi in vert_indices: NvTriStrip.stdin.write(str(vi).encode() + " ".encode())


print("STEP 1")
mashit = NvTriStrip.stdout.readline()
print("STEP 2")

stripcount = int(mashit)
if stripcount < 1: raise Exception("NvTriStrip returned 0 strips. Aborting")

nativelist = []
striptype = int(NvTriStrip.stdout.readline())
nativelength = int(NvTriStrip.stdout.readline())
nativelist.extend(map(int, NvTriStrip.stdout.readline().split()))

the above script works perfectly in python. the output is:

Code: Select all

[0, 1, 2, 3]
but when i try to run it in blender if freezes the main window, and the last line in console window is:

Code: Select all

NvTriStripper-cli.exe is in the root of the disk C:\

please help...

Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX » Sat Oct 06, 2012 8:34 pm

it's not intended to use a console beside Blender's interface...

but if you open Blender's console window, you should be able to use and input()

sys.stdout.readline() gives me error:
io.UnsupportedOperation: not readable
I'm sitting, waiting, wishing, building Blender in superstition...

Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Sat Oct 06, 2012 9:57 pm

No idea what your exe is doing, but you might try putting in a flush after the write, just in case blender is still waiting on the I/O to finish.

Posts: 0
Joined: Sat Oct 06, 2012 9:37 am

Post by heskn » Wed Oct 10, 2012 11:30 am

thank you guys for your replies. thanks god the flush() thing managed the thing - now i can create triangle strips without rewriting old 2.49 scripts :)

Post Reply