1

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!

4
  • 1
    Hm, what about print? Am I missing something? Commented Mar 27, 2012 at 22:32
  • print goes to stdout and stderr I need it to go to cout and cerr. Commented Mar 27, 2012 at 23:18
  • It depends on how the C++ application captures the output... If it reassigned the actual low-level file-handles then print in Python will work, otherwise you might have to make special Python functions to be called instead of print. Commented Mar 28, 2012 at 5:58
  • Any idea how this special functions would be? Print simply does not work I tried it already... Commented Mar 29, 2012 at 13:46

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.