java - Controlling stdout/stderr from Jython -
i calling function in java library jython prints stdout. suppress output jython script. attempt python idiom replacing sys.stdout file object (stringio), not capture output of java library. i'm guessing sys.stdout not affect java program. there standard convention redirecting or suppressing output programatically in jython? if not ways can accomplish this?
you can use system.setout, this:
>>> java.lang import system >>> java.io import printstream, outputstream >>> oldout = system.out >>> class nooutputstream(outputstream): ... def write(self, b, off, len): pass ... >>> system.setout(printstream(nooutputstream())) >>> system.out.println('foo') >>> system.setout(oldout) >>> system.out.println('foo') foo note won't affect python output, because jython grabs system.out when starts can reassign sys.stdout you'd expect.
Comments
Post a Comment