从PowerShell或C#的perl模块调用特定函数

本文关键字:调用 函数 模块 perl PowerShell | 更新日期: 2023-09-27 18:24:13

我有一个perl脚本文件(.pm),它有很多功能,比如下面的

sub check_row {
    my ($class, %args) = @_;
.......
sub find_value {
    my ($class, %args) = @_;
.......

有什么方法可以通过C#或Powershell调用特定的函数吗?我不允许对.pm文件进行任何更改。我对此一无所知,因为我在互联网上看到的教程只讨论了运行perl模块,而没有调用任何特定的函数以及传递和检索值。

从PowerShell或C#的perl模块调用特定函数

您不能直接从PowerShell或C#使用Perl模块(your_module.pm)。您需要运行使用以下模块的Perl脚本(your_script.pl):

#!/usr/bin/env perl
use strict;
use warnings;
use Your::Module qw(find_value);
find_value ...;

或者至少将代码字符串作为命令行参数传递给Perl解释器,正如Mathias R.Jessen在评论中指出的那样:

perl.exe -w -MYour::Module -e 'find_value ...;'

有关进一步的研究,您可以查看Win32-PowerShell-IPC-0.02。文件说明如下:

此模块启动一个捕获的子PowerShell进程,您可以向该进程提交命令并接收结果。现在都是文本,但Perl擅长于这种混乱的东西。