0

I have a command file (.cmd) which I use to launch Abaqus command line windows. Then, I use the command 'abaqus python test.py' to launch python command inside Abaqus.

Now, I would like to use a python script to do that. 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)
2
  • what are you trying to do ? run a script that does stuff in CAE or run a script that does some analysis etc (but no CAE tasks) ? Commented Jul 12, 2016 at 19:36
  • A script that run analysis (read odb file) so no CAE tasks Commented Jul 13, 2016 at 8:37

2 Answers 2

1

Using .cmd-file:

This way might work with cmd file:

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.

Easiest way:

Just add the folder with abaqus commands (typical path C:\Abaqus\Commands) into the PATH variable of the system. This will give the access to commands like abaqus, abq6141 etc. in cmd directly.

When just use the following in your script:

subprocess.call("abaqus python test.py")

Using .bat-file:

If the configuration of PATH variable is impossible and the first way does not work, .bat-files from abaqus can be used as follows:

abaqusPath = "C:\\Abaqus\\Commands\\abaqus.bat "
args = AbaqusPath + "python test.py"
subprocess.call(args)
Sign up to request clarification or add additional context in comments.

2 Comments

Could I get the return of subprocess call ? To know if something went wrong ?
Yes, as I understand all of them return the value of exit. Just assign it to some variable, for instance a = subprocess.call(). Then you can check if it is non-zero.
1

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'])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.