简体   繁体   English

从 python 脚本执行命令行程序(Abaqus-python 脚本)

[英]Executing command line program (Abaqus-python script) from python script

I am trying to run an Abaqus-python script file from another python script executed in Spyder (python 3.7, windows 10).我正在尝试从在 Spyder 中执行的另一个 python 脚本(python 3.7,windows 10)运行 Abaqus-python 脚本文件。

If I run the following command in CMD abaqus cae -noGUI model.py the code executes as expected.如果我在 CMD abaqus cae -noGUI model.py中运行以下命令,代码将按预期执行。 However, if I try to run cp = subprocess.run('abaqus cae -noGUI model.py',shell=True) I don't get any output.但是,如果我尝试运行cp = subprocess.run('abaqus cae -noGUI model.py',shell=True)我没有得到任何 output。 Below is what is returned in cp.以下是 cp 中返回的内容。

在此处输入图像描述

Notes:笔记:

  1. The Abaqus-python file I am trying to run is in the same folder as the python script I have.我尝试运行的 Abaqus-python 文件与我拥有的 python 脚本位于同一文件夹中。
  2. I have tried various sp.call, sp.run, os.systems in different string and list formats.我尝试了不同字符串和列表格式的各种 sp.call、sp.run、os.systems。
  3. "C:\Abaqus\Commands" and "C:\SIMULIA\Commands" are both in my PATH environment variable. “C:\Abaqus\Commands”和“C:\SIMULIA\Commands”都在我的 PATH 环境变量中。
  4. I think the -noGUI call is important to the problem.我认为 -noGUI 调用对问题很重要。 I can't seem to find others on SO with this issue.我似乎在这个问题上找不到其他人。

After a fair amount of digging, I think the issue is that the PATH for my python install is done thought Anaconda so I have a different path this vs CMD.经过大量挖掘后,我认为问题在于我的 python 安装的 PATH 已经完成,因为 Anaconda 所以我的路径与 CMD 不同。 I fixed this by adding the full Abaqus location to the command.我通过将完整的 Abaqus 位置添加到命令来解决此问题。 See below.见下文。

subprocess.call(r'C:\SIMULIA\Commands\abaqus job=Job-1 ask_delete=OFF interactive', shell=True) subprocess.call(r'C:\SIMULIA\Commands\abaqus job=Job-1 ask_delete=OFF interactive', shell=True)

I am not sure what your problem is due to, but note that Abaqus scripting is based on python 2.7, therefore you might need to downgrade it我不确定您的问题是什么引起的,但请注意 Abaqus 脚本基于 python 2.7,因此您可能需要降级它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM