Input on executable file from Python file -


my problem this: working on trying use python interface program (already made fortran) user can introduce input opening program , sending input, never works reason.

i import following:

import simpleguitk,os subprocess import popen,pipe,stdout 

using different answers have found around here, have written following:

p = popen(['potscat2.exe'],stdin=pipe)#,stdout=pipe,stderr=stdout) p.communicate(str(opmenu[0])+"\n"+str(opmenu[1])+"\n"+str(opmenu[2])+"\n"+str(opmenu[3][0]*pow(10,opmenu[3][1]))+"\n","utf-8") 

alternatively, there following:

p = popen(['potscat2.exe'],stdin=pipe)#,stdout=pipe,stderr=stdout) p.stdin.write(str(opmenu[0])) p.stdin.write(str(opmenu[1])) p.stdin.write(str(opmenu[2])) p.stdin.write(str(opmenu[3][0]*pow(10,opmenu[3][1]))) 

neither of alternatives works, though.

the former gives error:

exception in tkinter callback traceback (most recent call last): file "c:\python34\lib\tkinter\__init__.py", line 1533, in __call__ return self.func(*args) file "c:\python34\lib\site-packages\simpleguitk\input.py", line 90, in _mouse_click self._mouse_click_handler(pos)   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 357, in mouse_control     b.mouse_act(position)   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 106, in mouse_act     self.action()   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 112, in <lambda>     butf = button((1050,800),(120,50),"finish", lambda : finish())   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 280, in finish     p.communicate(str(opmenu[0])+"\n"+str(opmenu[1])+"\n"+str(opmenu[2])+"\n"+str(opmenu[3][0]*pow(10,opmenu[3][1]))+"\n","utf-8")   file "c:\python34\lib\subprocess.py", line 954, in communicate     endtime = _time() + timeout typeerror: unsupported operand type(s) +: 'float' , 'str' 

the latter gives error:

exception in tkinter callback traceback (most recent call last):   file "c:\python34\lib\tkinter\__init__.py", line 1533, in __call__     return self.func(*args)   file "c:\python34\lib\site-packages\simpleguitk\input.py", line 90, in _mouse_click     self._mouse_click_handler(pos)   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 357, in mouse_control     b.mouse_act(position)   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 106, in mouse_act     self.action()   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 112, in <lambda>     butf = button((1050,800),(120,50),"finish", lambda : finish())   file "c:\users\miguel\pythonworkplace\potscat\potscat2.py", line 281, in finish     p.stdin.write(str(opmenu[0])) typeerror: 'str' not support buffer interface 

could me? know, using python 3.4 on windows 7. executable has receive data 1 one, independent each other.

help?

edit: taking "utf-8" first alternative takes out typeerror mentioned (it counting timeout), gives, in exchange, same typeerror in other possibility.

opmenu defined as

opmenu = [0,0,0,[0,0]] 

all values integers, save opmenu[3][0], float.

p.communicate(str(opmenu[0])+"\n"+str(opmenu[1])+"\n"+str(opmenu[2])+"\n"+str(opmenu[3][0]*pow(10,opmenu[3][1]))+"\n","utf-8") 

the second argument communicate timeout. giving "utf-8", not valid value. timeout should number or none.

try calling communicate 1 argument.

p.communicate(str(opmenu[0])+"\n"+str(opmenu[1])+"\n"+str(opmenu[2])+"\n"+str(opmenu[3][0]*pow(10,opmenu[3][1]))+"\n") 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -