none
I need to run a TCL script in python, my TCL script also has a user-defined(internal) package RRS feed

  • Question

  • 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!

    Tuesday, January 15, 2013 5:47 PM

Answers

  • This forum is for Microsoft Project, a desktop scheduling application.  Please post in a more appropriate forum.

    Andrew Lavinsky [MVP] Blog: http://azlav.umtblog.com Twitter: @alavinsky

    Tuesday, January 15, 2013 5:56 PM
    Moderator