1

Hi I have a C# program that opens a process and calls a python script to execute some operations on an image.

Currently, I'm saving the image to the disk and passing the path to my python script as an argument, but I want to speed it up and wonder if I can use memory stream instead.

var psi = new ProcessStartInfo();
psi.FileName = @"python_interpreter_path";
var script = @"my_python_script_path";
psi.Arguments = script;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
var errors = "";
var results = "";
using (var process = Process.Start(psi))
{
       errors = process.StandardError.ReadToEnd();
       results = process.StandardOutput.ReadToEnd();
       Console.WriteLine(errors);
       Console.WriteLine(results);
}

I've got a python script that can decode a data stream and open it as an image using cv2.imread(). But I clueless on what to do with my c# code.

Any help is welcome! Thanks

Felipe Cunha
  • 166
  • 1
  • 5
  • 1
    Learn something about either Memory Mapped File, or Named Pipe. – aepot Jul 04 '21 at 21:30
  • Does this answer your question? [Sharing data across processes on linux](https://stackoverflow.com/questions/7107305/sharing-data-across-processes-on-linux) – Lenormju Jul 05 '21 at 07:12

1 Answers1

0

Thanks guys for indicating a direction. Pipes seems to be a great alternative for this problem.

I've tested this solution and it works: Named Pipes between C# and Python

On the python side pywin32 will need to be installed: python -m pip install pywin32

Thanks

Felipe Cunha
  • 166
  • 1
  • 5