I need to run a TCL script in python, my TCL script also has a user-defined(internal) package I tried these scripts:
1.
import Tkinter
import socket
def TCLRun():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 5006))
root = Tkinter.Tk()
## root.tk.eval('package require XXX')
tcl_script ="""
package require XXX
set YYY [COMMAND FROM PACKAGE]
puts $YYY
} """
# call the Tkinter tcl interpreter
root.tk.call('eval', tcl_script)
root.mainloop()
with this error:
import TCLCall
>>> TCLCall.TCLRun()
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
TCLCall.TCLRun()
File "C:\Users\XXX\Desktop\PKT\TCLCall.py", line 24, in TCLRun
root.tk.call('eval', tcl_script)
TclError: can not find channel named "stdout"
and,
2.
import Tkinter
root=Tkinter.Tk()
root.tk.eval('package require XXX')
root.tk.eval('set YYY COMMAND')
returns error about sdtout!
other one:
3.
import subprocess
p = subprocess.Popen(
"tclsh tcltest.tcl",
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
print stdout
print stderr
returns the following error:
can't find package __teapot__
while executing
"package require __teapot__"
none of them working, please help me with this issue!
I can use some commands that operating something on our product with following code:
import socket
import time
def Sckt():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 5006))
s.send('0 COMMAND \r\n')
that would give you some ideas!
thank,
tclsh tcltest.tclthe errors seem to come from tcl, so the python around your tcl might only make it harder to understand the underlying problem.