Ask Your Question

Suppress PSSE output entirely

asked 2015-03-05 09:14:36 -0500

JDRobers gravatar image

updated 2015-03-06 07:38:06 -0500

Hello forum,

I have managed to find quite a few roundabout solutions to my problems with PSSE, but this one continues to annoy me.

I want to make it so that when using psspy, I do not get tons of text printed to the terminal. There was a time when I was able to circumvent this by using psspy.report_output to send the output to a text file, but that no longer appears to work.

According to the API manual, there is an option "6" for report_output that states "no output." That would be great if that option actually delivered what it promised, but I still get tons of text output to the command terminal. Is there an easy way to get rid of this?


I have tried chip's approach using contextmanager and setting sys.stdout to os.devnull, but to no avail. I even tried breaking up the use of the "with" statement into two methods like so:

OLD_STDOUT = sys.stdout    #Keep track of what the original output to terminal was
def silence(file_object = None):
    Discard stdout (i.e. write to null device) or
    optionally write to given file-like object.
    if file_object is None:
        file_object = open(os.devnull, 'w')

        sys.stdout = file_object
        sys.stdout = OLD_STDOUT

def unsilence():
    Reset stdout to the terminal like normal
    sys.stdout = OLD_STDOUT

And then I even tried something like:

print "Checkpoint 0"
print "Checkpoint 1"

However, the text created from psseinit still gets to the terminal somehow. Oddly enough, checkpoint 1 does not get printed. I'm stumped.

edit retag flag offensive close merge delete


My favorite way by far is to redirect with a contextmanger like this [example]( Here is my [gist]( I created as another example.

chip gravatar imagechip ( 2015-03-05 13:43:39 -0500 )edit

I tried the contextmanager approach just now, creating the silence() function that you showed in your example, verbatim. Unfortunately, I am still getting the output to console, even for something as simple as containing psseinit inside a "with silence()" block.

JDRobers gravatar imageJDRobers ( 2015-03-06 07:17:59 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2015-03-28 17:52:29 -0500

wassup_doc gravatar image

I just thought I would add a bit to the answer. @chip provided a great suppression solution by redirecting PSS/e to python and then directing python to save stdout to a file. I have a very similar tatic in my code, and this workflow is great for being able to revisit all of the regurgitation that PSS/e does (especially for debugging purposes). However, since file I/O is one of the most costly things you can do (i.e open, write to, close a file), it may (depending on what you are doing) be useful and/or save time to actually suppress PSS/e output instead of just hiding it in a file.

One thing that I did not see covered here was how to do this, as well as a follow-up to @JDRobers's comment:

According to the API manual, there is an option "6" for report_output that states "no output." That would be great if that option actually delivered what it promised, but I still get tons of text output to the command terminal.

I think what is being missed here, is what you are actually doing in PSS/e because that governs what suppression API function you want to use. Basically what I am saying is that psspy.report_output() is not the only output API.

The four API's that you want to use at the beginning of your simulation are:


These will suppress all PSS/e output. Except I cannot figure out how to suppress the copyright and 3 lines of header for PSS/e initialization. so you still get the following on your command prompt:

PSS(R)E Version 33
 Copyright (c) 1976-2015
 Siemens Industry, Inc.,
 Power Technologies International                            (PTI)
 This program is a confidential  unpublished  work  created  and  first
 licensed in 1976.  It is a trade secret which is the property of  PTI.
 All use,  disclosure,  and/or reproduction not specifically authorized
 by  PTI  is prohibited.   This  program is protected  under  copyright
 laws  of  non-U.S.  countries  and  by  application  of  international
 treaties.  All  Rights  Reserved  Under  The  Copyright  Laws.



             INITIATED ON SAT, MAR 28 2015  15:15

Hope that helps someone out!

edit flag offensive delete link more


Using your advice and combining it with the silence() method for the initial copyright printout, I have acheived my goal. Thanks!

JDRobers gravatar imageJDRobers ( 2015-03-31 13:03:04 -0500 )edit

answered 2015-03-06 10:12:55 -0500

chip gravatar image

updated 2015-03-06 10:28:58 -0500

I prefer to redirect STDOUT using a contextmanager so that I am sure that STDOUT goes back to normal after I am done capturing/ignoring it. The contextmanger will do the right thing if there is an exception, and plays nicely with pdb.set_trace(). If I don't use a contextmanger it still works, but invariably my code throws an exception while STDOUT is being captured, and then everything is a mess because I can't see STDOUT.

Usually if redirecting STDOUT is failing it is because I forget the line redirect.psse2py(). Here is a simple example with psseinit()

import sys
import os

import pssepath
import psspy

import redirect

import contextlib
def silence(new_target=None):
    # sometimes you don't care about messages.
    if new_target is None:
        new_target = open(os.devnull, 'w')
    old_target, sys.stdout = sys.stdout, new_target # replace sys.stdout
        yield new_target # run some code with the replaced stdout
        sys.stdout = old_target # restore to the previous value

if sys.argv[1] == 'silent':
    with silence():

And the results from running it in the CLI:

>python silent

>python verbose

 PSS(R)E Version 33
 <... snip ...>
 treaties.  All  Rights  Reserved  Under  The  Copyright  Laws.



             INITIATED ON FRI, MAR 06 2015   9:57

Without redirect.psse2py()

If you do not run the redirect.psse2py() function, STDOUT will be captured for everything except PSSE. (I do not understand how PSSE is making text appear on the screen without STDOUT).

If we use our example code above and leave out the redirect.psse2py(), we see that normal python is silenced:

In [1]: print "Checkpoint 0"
Checkpoint 0

In [2]: with silence():
   ...:     print "Checkpoint 1"
In [3]:

But PSSE is still noisy:

In [3]: with silence():
   ...:     psspy.psseinit(10)

 PSS(R)E Version 33
 Copyright (c) 1976-2015
 <.......... snip ..............>
edit flag offensive delete link more


Thank you! That redirect.psse2py() was the missing link.

JDRobers gravatar imageJDRobers ( 2015-03-06 11:41:32 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower


Asked: 2015-03-05 09:14:36 -0500

Seen: 2,710 times

Last updated: Mar 28 '15