如何在 Python 的文件夹中运行 Tcl 脚本? [英] How to run a Tcl Script in a folder in Python?
问题描述
我有一个 Tcl 脚本存储在 C:/我如何从 Python 运行它?(不是用python写Tcl脚本然后运行)
I have a Tcl script stored in C:/ How do I run it from Python? (It is not write the Tcl script in python and then run it)
为了澄清我的问题,首先我有一个名为 oommf 的基于 Tcl 的程序,用于模拟.这是一个简短的介绍 http://math.nist.gov/oommf/
To clarify my question, firstly I have a Tcl-based programme called oommf, which is used for simulation. Here is a short introduction http://math.nist.gov/oommf/
我用这个程序写了一些脚本,想用python来运行一系列的模拟,然后提取数据来绘制一些图形..mif 格式的脚本,我想做的是
I wrote some scripts by this programme and would like to use python to run a series of simulation and then extract the data to plot some graph. The script in in .mif format, and what I wish to do is
- 使用python生成.mif脚本,每次使用不同的参数
- 使用python调用基于Tcl的程序运行脚本
- 保存数据并使用python提取并绘制图形
Tcl 程序采用 .tcl 格式.
The Tcl programme is in .tcl format.
Tcl 程序也可以在命令行中运行.我听说有一些方法可以在 python 中模拟命令行(在 windows 环境中),但我不知道,如果有人知道,它会很有帮助.
The Tcl programme can also be run in command line. I heard that there was some way to simulate command line in python(in windows environment), but I don't know and if any one knows, it would help much.
(对不起,我之前的编程知识只有一点 C,这就是为什么我的问题可能含糊不清,因为我不知道如何更清楚地描述它)
(Sorry my prior knowledge for programming is only a bit in C, that's why my question might be ambiguous because I don't know how to describe it more clearly)
推荐答案
尝试使用 subprocess.call
subprocess.call 将避免必须处理各种 shell 的引用约定的问题.它接受一个列表,而不是一个字符串,所以参数更容易分隔.即
subprocess.call will avoid problems with having to deal with quoting conventions of various shells. It accepts a list, rather than a string, so arguments are more easily delimited. i.e.
import subprocess
subprocess.call(['C:\\Temp\\a b c\\Notepad.exe', 'C:\\test.txt'])
这篇关于如何在 Python 的文件夹中运行 Tcl 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!