1

以下のスクリプトで python を介して TCL を実行すると、ユーザー定義のパッケージを必要とする TCL スクリプトがあります。

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

次のエラーを返します。

can't find package __teapot__

    while executing

"package require __teapot__"

TCL は tclsh 環境で動作します。Python がパッケージを認識しないという私のセットアップで何かが間違っていると思います!

4

1 に答える 1

0

環境変数が明示的に渡されていないのだろうか。どうですか:

import subprocess
import os
p = subprocess.Popen(
    "tclsh tcltest.tcl",
    env=os.environ,
    shell=True,
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
print stdout
print stderr

アップデート

それは違いがないので、次の行を tcltest.tclファイルの最初の行に貼り付けて、出力を比較します。

puts ">>$auto_path<<"

auto_path変数は2つのケースで異なると思われます。この変数は、Tcl がパッケージを見つけるために使用する 1 つの方法です。

于 2013-01-11T21:56:28.370 に答える