Call .NET from Perl

I have a Perl script and need to call a method that is in a .NET assembly. I found this technique , but it was very important for a one-time Perl script, so I did not use it. I ended up writing a trivial .NET console application as a wrapper for the call I needed and connected my Perl script with a wrapper using Console.In / Console.Out / IPC::Open2.

This turned out to be problematic because the .NET method StreamReader.ReadToEnddid not seem to be able to detect the end of the file on Console.In, even after my Perl script closed the end of this pipe!

I ended up hacking a solution that worked for my purposes, but is there a better way to call .NET from Perl?

+3
source share
1 answer

"The StreamReader.ReadToEnd method did not seem to be able to detect the end of the file on Console.In"

It seems you were able to interact with .NET. But you called StreamReader.ReadToEndon the console tab. This can be problematic even without Perl. Excerpt from this:

ReadToEnd assumes that the thread knows when it has reached its goal. For interactive protocols in which the server sends data only when you ask for it and does not close the connection, ReadToEnd can be blocked indefinitely and should be avoided.

Your code may be right, but you need to use a different method for your purpose.

Edit:

"I ended up writing a trivial .NET console application as a wrapper"

, (Perl .NET). (Console.In/Out) , StreamReader.Read StreamReader.ReadLine .NET , , . null, EOF.

, Perl, .NET. I.e., , .NET , Perl, . Perl . , PerlSharp.

+3

Source: https://habr.com/ru/post/1757816/


All Articles