且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用tcl exec命令运行python脚本

更新时间:2022-04-06 04:27:26

您的tcl脚本定义了执行python脚本的过程,但未调用该过程.将呼叫添加到您的tcl脚本:

Your tcl script defines a procedure to execute a python script, but does not call the procedure. Add a call to your tcl script:

#! /usr/bin/tclsh
proc call_python {} {
    set output [exec python helloWorld.py]
    puts $output
}

call_python

此外,通过exec启动的进程写入stdout的任何内容都不会显示在终端中.您需要从exec调用中捕获它,并且显式地自己打印:

Also, anything written to stdout by the process launched via exec will not get displayed in your terminal. You'll need to capture it from the exec call, and print is explicitly yourself:

#! /usr/bin/tclsh
proc call_python {} {
    set output [exec python helloWorld.py]
    puts $output
}

call_python