如何在Python中的文件夹中运行Tcl脚本?
我有一个存储在C中的Tcl脚本:/ 如何从Python运行它? (不是用python编写Tcl脚本然后运行) 为了澄清我的问题,首先我有一个名为oommf的基于Tcl的程序,用于模拟。这里是一个简短的介绍 我用这个程序编写了一些脚本,希望使用python运行一系列模拟,然后提取数据来绘制一些图形。脚本是.mif格式的,我想做的是如何在Python中的文件夹中运行Tcl脚本?,python,tcl,Python,Tcl,我有一个存储在C中的Tcl脚本:/ 如何从Python运行它? (不是用python编写Tcl脚本然后运行) 为了澄清我的问题,首先我有一个名为oommf的基于Tcl的程序,用于模拟。这里是一个简短的介绍 我用这个程序编写了一些脚本,希望使用python运行一系列模拟,然后提取数据来绘制一些图形。脚本是.mif格式的,我想做的是 使用python生成.mif脚本,每次使用不同的参数 使用python调用基于Tcl的程序来运行脚本 保存数据并使用python提取和绘制图形 Tcl程序采用.Tcl格
import subprocess
subprocess.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
这里有一个建议。很多都是猜测,因为我不知道你到底想做什么
import subprocess
# 1. Code to generate .mif script, for example: my.mif
with open('my.mif', 'wb') as f:
f.write('something')
# 2. Launch oommf. I am guessing the command line, based on your
# description and based on what the location of tclsh in my system
cmd = ['C:/Tcl/bin/tclsh.exe', 'C:/oomf.tcl', 'my.mif']
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
# 3. Now, you can do something with stdout and stderr if needed
# Below is just an example
with open('data.txt', 'wb') as f:
f.write(stdout)
您应该更新您的答案,使其与问题更密切相关(即,
tclsh.exe
而不是Notepad.exe
,以及test.tcl
而不是test.txt
),谢谢您的建议。我已经更新了我的问题,你能帮点忙吗?@littleHui:你需要什么帮助?