locked
Communication between Python and C# RRS feed

  • Question

  • Hi,

    I have a python script and a C# wpf application.I am calling the C# wpf application using the os.popen() command.

    Requirements:

    An event in C# when triggered should pass a message to the python script. This should happen whenever the C# event is triggered.

    On the other hand the python script should continuously listen to these messages and should be able to handle these messages.

    Can anybody help me on this?

    Thanks and regards

    Chinmay

    Thursday, January 24, 2013 4:03 PM

Answers

  • Be aware that in this it depends what Pyton expects to get, however take a look at this page about sendmessage

    http://stackoverflow.com/questions/5083954/send-message-in-c-sharp


    Success
    Cor

    • Marked as answer by Bob Shen Monday, February 4, 2013 8:00 AM
    Thursday, January 24, 2013 4:31 PM
  • You need to use a pipe to connect the C# application to to the python script.  the pythoon should be looking a standard input using readline to get the input.  The c# should send output to the python script standard input and make sure the is the linefeed at the end of each command.

    jdweng

    • Marked as answer by Bob Shen Monday, February 4, 2013 8:00 AM
    Thursday, January 24, 2013 4:35 PM
  • There are quite a few options - 

    Using a pipe is a good option - both C# and python support pipes well, so you can use this for IPC.  

    Another option is to use Python for .NET to access the WPF application's internals without launching it as a process. If you reworked it as a library, python could be used to "control" it, and subscribe to events directly.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Bob Shen Monday, February 4, 2013 8:00 AM
    Thursday, January 24, 2013 5:32 PM

All replies

  • Be aware that in this it depends what Pyton expects to get, however take a look at this page about sendmessage

    http://stackoverflow.com/questions/5083954/send-message-in-c-sharp


    Success
    Cor

    • Marked as answer by Bob Shen Monday, February 4, 2013 8:00 AM
    Thursday, January 24, 2013 4:31 PM
  • You need to use a pipe to connect the C# application to to the python script.  the pythoon should be looking a standard input using readline to get the input.  The c# should send output to the python script standard input and make sure the is the linefeed at the end of each command.

    jdweng

    • Marked as answer by Bob Shen Monday, February 4, 2013 8:00 AM
    Thursday, January 24, 2013 4:35 PM
  • There are quite a few options - 

    Using a pipe is a good option - both C# and python support pipes well, so you can use this for IPC.  

    Another option is to use Python for .NET to access the WPF application's internals without launching it as a process. If you reworked it as a library, python could be used to "control" it, and subscribe to events directly.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Bob Shen Monday, February 4, 2013 8:00 AM
    Thursday, January 24, 2013 5:32 PM