4

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?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
UN4
  • 587
  • 5
  • 19

1 Answers1

9

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.

hgazibara
  • 1,832
  • 1
  • 19
  • 22
  • Perfect answer! Thanks! It is exactly what i wanted and it does exactly what it supposed to do! – UN4 Apr 12 '16 at 13:56
  • Could you please examine these "other ways" a little bit? I tried to override the members of abaqus.sys with the members of sys, so I could use the standard print command, but it didn't work. – flxh Oct 18 '17 at 07:38
  • @flxh Most probably I was thinking of `logging` module, which offers a lot more functionality than the pure printing approach. – hgazibara Oct 18 '17 at 08:20
  • Thank you. But could you please explain what ">>" is after the print? – Johann Bzh May 20 '20 at 09:41
  • @JohannBzh That is part of the print statement's syntax in Python 2 which allows you to specify the destination for the output produced by the print statement. It can be any file object, with standard output (`stdout`) being the default. – hgazibara May 20 '20 at 15:03