2

I have a python project back-end with a c# GUI front-end both in the same solution. The python project uses libraries such as opencv, dlib etc. How and what is the best way to start the python script from my c# project and also have communications between them. The python project has to accept arguments for startup and continuously transmit information back to the c# project.

3 Answers 3

2

You will have to use something like sockets in python to continuously transmit the data to c#.

Or you could also try to make a REST API using Flask and then have your C# GUI make an HTTP GET/POST request to your Flask Endpoint with the required arguments, after the processing is done in python, you can return the response as a JSON and render it in your GUI.

You can check out the Flask Docs, its easy to get started with it. https://flask.palletsprojects.com/en/1.1.x/quickstart/

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

1 Comment

Yes that are some great ideas thank you, but how would i spin up the python project through my c# code?
1

You can execute python code by Process.start in c# project. For example: ExecutePythonScript

1 Comment

Is there a way to run it that keeps the current python environment as i have it in this specific project?
1

You can start the Python script with Process Start like:

using System.Diagnostics;

public void StartProcess()
    {
        var processStartInfo = new ProcessStartInfo();
        processStartInfo.FileName = "your_python_path";
        var script = "your_script_path";

        processStartInfo.Arguments = $"\"{script}\"";
        processStartInfo.UseShellExecute = false;
        processStartInfo.CreateNoWindow = true;
        processStartInfo.RedirectStandardOutput = true;
        processStartInfo.RedirectStandardError = true;

        var process = Process.Start(processStartInfo);
    }

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.