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

2
  • 1
    Learn something about either Memory Mapped File, or Named Pipe. Commented Jul 4, 2021 at 21:30
  • Does this answer your question? Sharing data across processes on linux Commented Jul 5, 2021 at 7:12

1 Answer 1

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

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.