1

I have a Python Script that I run from a C++ GUI Application. I want to get the output of that Script into a Python Console and have the ability to manipulate them before calling another Python Function from C++.

My Question: Is that possible by just redirection stdin & stdout to Files? Is there a better way using pure python?

Please note that I don´t want to spawn the console from the C++ Programm but from outside the C++ Programm.

1 Answer 1

1

You should be able to adapt the approach in this answer to your needs. The example it links to uses UDP sockets for transferring commands to/from the interactive interpreter, but you could easily change that to pull data from stdin (or wherever) instead.

The key thing to take away from the example is the use of the builtin InteractiveConsole's push() method to determine whether the input is:

  1. Well-formed Python snippet that may be evaluated as-is
  2. A syntactically invalid snippet, or
  3. A snippet that may become valid, but more input is needed
Sign up to request clarification or add additional context in comments.

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.