Perl-如何使用在另一个Perl脚本中的模块中创建的进程句柄 [英] Perl - How to use a process Handle created in a Module in another Perl Script

查看:74
本文介绍了Perl-如何使用在另一个Perl脚本中的模块中创建的进程句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最终,我想做的是在模块中启动一个进程,并在另一个脚本中实时解析输出.

Ultimately, what I want to do is to start a process in a module and parse the output in real time in another script.

我想做什么:

  • 打开进程处理程序(IPC)
  • 在 模块
  • Open a process Handler (IPC)
  • Use this attribute outside of the Module

我要如何做并失败:

  • 打开流程处理程序
  • 将处理程序保存在模块的 属性
  • 在模块外部使用属性.
  • Open the process handler
  • Save the handler in a module's attribute
  • Use the attribute outside the module.

代码示例:

#module.pm

$self->{PROCESS_HANDLER};

sub doSomething{
  ...
  open( $self->{PROCESS_HANDLER}, "run a .jar 2>&1 |" );
  ...
}


#perlScript.pl

my $module = new module(...);
...
$module->doSomething();
...
while( $module->{PROCESS_HANDLER} ){
  ...
}

推荐答案

您的while语句缺少readline迭代器,原因是:

Your while statement is missing a readline iterator, for one thing:

while( < {$module->{PROCESS_HANDLER}} > ) { ...

while( readline($module->{PROCESS_HANDLER}) ) { ...

这篇关于Perl-如何使用在另一个Perl脚本中的模块中创建的进程句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆