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
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/
1 Comment
You can execute python code by Process.start in c# project. For example: ExecutePythonScript
1 Comment
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);
}