[英]Launch python script with abaqus command
I have a command file (.cmd) which I use to launch Abaqus command line windows.我有一个命令文件 (.cmd),我用它来启动 Abaqus 命令行窗口。 Then, I use the command 'abaqus python test.py' to launch python command inside Abaqus.
然后,我使用命令 'abaqus python test.py' 在 Abaqus 中启动 python 命令。
Now, I would like to use a python script to do that.现在,我想使用 python 脚本来做到这一点。 I try something like this but doesn't work.
我尝试这样的事情,但不起作用。 Someone know the trick ?
有人知道诀窍吗?
Thanks !!谢谢!!
import subprocess
AbaqusPath=r"C:\Abaqus\script\abaqus.cmd"
args= AbaqusPath + "-abaqus python test.py"
subprocess.call(args)
This way might work with cmd file:这种方式可能适用于 cmd 文件:
abaqusPath = "C:\\Abaqus\\script\\abaqus.cmd /C"
args = AbaqusPath + "abaqus python test.py"
subprocess.call(args)
Flag /C is needed to run command and then terminate.需要标志 /C 来运行命令然后终止。
Just add the folder with abaqus commands (typical path C:\\Abaqus\\Commands) into the PATH variable of the system.只需将带有 abaqus 命令的文件夹(典型路径 C:\\Abaqus\\Commands)添加到系统的 PATH 变量中。 This will give the access to commands like abaqus, abq6141 etc. in cmd directly.
这将允许直接在 cmd 中访问 abaqus、abq6141 等命令。
When just use the following in your script:在脚本中使用以下内容时:
subprocess.call("abaqus python test.py")
If the configuration of PATH variable is impossible and the first way does not work, .bat-files from abaqus can be used as follows:如果无法配置 PATH 变量且第一种方法不起作用,则可以使用 abaqus 中的 .bat 文件,如下所示:
abaqusPath = "C:\\Abaqus\\Commands\\abaqus.bat "
args = AbaqusPath + "python test.py"
subprocess.call(args)
I've never had any success using just string arguments for subprocess functions.我从未仅使用字符串参数作为子流程函数取得任何成功。
I would try it this way:我会这样尝试:
import subprocess
abaqus_path = r"C:\Abaqus\script\abaqus.cmd"
subprocess.call([abaqus_path, '-abaqus', 'python', 'test.py'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.