0

I know the title sounds a little weird, but I'm wondering if there is a good way to pass a string value in python to a string value in c#?

I have a neural-network that I am using in python to detect objects in an image. For each object that is detected, it also gets an identifier of what the neural-network thinks it detected which is stored in a string. I also have a C# application that I am creating, that runs my Python script through a bat file. What I want to do is get the string identifier from my Python script so I can use it as a string in my C# application. I've though about using a txt file where I would output the string from my Python script and have my C# application read the txt back. Is there any better ways to achieve this out there?

3
  • 1
    docs.python.org/3/library/ipc.html Commented Apr 11, 2020 at 20:42
  • better? better how? what is wrong about you current ways of doing things? that works isn't it? what are you looking for. Commented Apr 11, 2020 at 20:44
  • @sommmen If I use a txt file then that's another file I have to work with, both writing to it and reading it back in the respective languages that I am using. I'm wondering if there is a way that I could just pass a python string strait into a c# string. Commented Apr 11, 2020 at 20:46

1 Answer 1

1

You can pass your string as a command line argument to the .net program (e.g. myprog.exe)

Then read it out with Environment.GetCommandLineArguments https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/

if you need to do communication back and forth the easiest way to achieve that is by using a TCP/UDP client/server. The are available in c# and python. There are other mechanisms like named pipes on windows but tcp is the easiest.

This actually has a good sample you could use, but google around; Send Data from [Python Client] to [C# Server] using Socket

This is called inter process communication btw, which is a great google term. Also see:

What is the simplest method of inter-process communication between 2 C# processes?

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.