Mac
Mac

Reputation: 3559

print to cout from embedded python

I am using python's very high level layer to embed some python code to a commercial application that supports a proprietary scripting language. The problem is that the application itself is coded in C++ and it has a embedded log window which displays cout and cerr. I was wondering if there is a way to print to cout/cerr from python... I already goggled a lot about it, but I cannot find a simple way to do it.

Thanks!

Upvotes: 1

Views: 2310

Answers (2)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799580

There is no simple way. The application itself must assign file-likes to sys.stdout and sys.stderr in order to capture them.

Upvotes: 1

Thanasis Petsas
Thanasis Petsas

Reputation: 4448

You can do it using these calls:

import sys
sys.stderr.write('blah blah\n')
sys.stdout.write('blah blah\n')

or alternatively using these ones:

print >> sys.stderr, 'blah blah'
print >> sys.stdout, 'blah blah'

Upvotes: 0

Related Questions