0

I'm calling a command line to run Abaqus from python interpreter. However, no Abaqus engine stats in this process. Only Matlab program is opening, dont know why. Does this command interact with my Matlab? Anyone could indicate anything wrong with my subprocess call? Thx

import subprocess
process=subprocess.call('abaqus', 'cae', 'script=C:\Users\Desktop\modelAExample.py')

If I run the following command from cmd directly, it will work

abaqus cae script=modelAExample.py
rifle123
  • 149
  • 1
  • 2
  • 15
  • Well, for one thing, there sure are a lot of unescaped backslashes in that pathname... – kindall Mar 28 '17 at 16:36
  • all thos args should be a single list, like : `subprocess.call(['abaqus', 'cae', 'script=C:\\Users\\Desktop\\modelAExample.py'])` (note added square brackets) – agentp Mar 28 '17 at 16:47
  • @agentp I tried this. But everytime I run this. Nothing happens only with the Matlab opened unexpected. – rifle123 Mar 28 '17 at 17:14
  • 1
    try using the full path for abaqus. see here http://stackoverflow.com/q/43037012/1004168. Do you want the abaqus GUI to open? If not use "noGUI=" instead of "script=" – agentp Mar 28 '17 at 17:18

1 Answers1

0

I was going to write a comment, but it wouldn't format this properly. It could be that your script is exiting and not waiting on the process.

Try this:

from subprocess import PIPE, Popen
import os

path = os.path.join("c:", "Users", "Desktop", "modelAExample.py")

if os.path.exists(path):
    proc = Popen(['abaqus', 'cae', 'script={}'.format(path)], stdout=PIPE)
    proc.communicate()

else: 
    print("Bad path")

Also, are you specifying the correct path to modelAExample.py? I don't see you specifying a username which usually follows C:\Users\

NuclearPeon
  • 5,743
  • 4
  • 44
  • 52
  • Yes, I just omitted the user name when typing this question. The code prints out Bad Path! However, the path is there exactly. – rifle123 Mar 29 '17 at 21:34
  • i think you need a slash in there `join("c:/",..` – agentp Mar 30 '17 at 01:22
  • @agentp According to this rated SO comment, you don't need the slash: http://stackoverflow.com/a/7767925/1703772. @rifle123 It looks like your path is incorrect. One way to verify your issue is by running `abaqus cae` and comparing the result with what you are seeing while specifying the `script` attribute. If the window opens in both modes, it's highly likely your path is wrong. – NuclearPeon Apr 01 '17 at 00:13