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

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

heskn
Posts: 2
Joined: Sat Oct 06, 2012 9:37 am

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

Postby 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())

NvTriStrip.stdin.write("-1\n".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()))

print(nativelist)

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

Code: Select all

STEP 1
STEP 2
[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

STEP_1

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

please help...

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

Postby 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

os.read() and input()

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

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

Postby 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.

heskn
Posts: 2
Joined: Sat Oct 06, 2012 9:37 am

Postby 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 :)


Return to “Python”

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests