Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing to terminal using Abaqus nogui python interface

When running abaqus nogui python script I would like to output the status of the script to the terminal. But when I do, e.g.:

print("Opening ODB...")
print("Plotting images...")

I also tried:

print "Opening ODB..."
print "Plotting images..."

and

sys.stdout.write("Opening ODB...")
sys.stderr.write("Plotting images...")

Nothing gets outputted to the terminal. Despite this my code runs fine and does everything it supposed to do.

Does anyone have any ideas how to solve this issue?

like image 748
UN4 Avatar asked Oct 20 '25 12:10

UN4


1 Answers

Abaqus automatically redefines standards output to its own custom object. To be precise, standard output gets set to an instance of abaqus.AbaqusStdout. This is what you would get if you were to, for example, write str(sys.stdout) to a file.

However, the original definition of Python's standard output is stored in sys.__stdout__. You could use it to redefine standard output again or directly use it for writing to it.

Since Abaqus installation is using Python older than 2.7, you could write

import sys

print >> sys.__stdout__, 'Opening ODB'

To make it cleaner, simply create a function, e.g. log, which will do the dirty work for you and then write only log('some message').

There are other ways you could do logging once you know the definition of the standard output, but this is then up to you to explore.

like image 94
hgazibara Avatar answered Oct 23 '25 00:10

hgazibara