异步运行perl的反引号
发布时间:2020-12-15 23:22:09 所属栏目:大数据 来源:网络整理
导读:现在我有一个perl脚本,在某个时刻,收集然后处理几个bash命令的输出,现在我就是这样做的: if ($condition) { @output = `$bashcommand`; @output1 = `$bashcommand1`; @output2 = `$bashcommand2`; @output3 = `$bashcommand3`;} 问题是,这些命令中的每一个
现在我有一个perl脚本,在某个时刻,收集然后处理几个bash命令的输出,现在我就是这样做的:
if ($condition) { @output = `$bashcommand`; @output1 = `$bashcommand1`; @output2 = `$bashcommand2`; @output3 = `$bashcommand3`; } 问题是,这些命令中的每一个都需要相当长的时间,因此,我想知道我是否可以同时运行它们. 解决方法
这听起来像
Forks::Super::bg_qx 的一个很好的用例.
use Forks::Super 'bg_qx'; $output = bg_qx $bashcommand; $output1 = bg_qx $bashcommand1; $output2 = bg_qx $bashcommand2; $output3 = bg_qx $bashcommand3; 将在后台运行这四个命令.用于返回值的变量($output,$output1等)是重载对象.您的程序将在下次在程序中引用这些变量时检索这些命令的输出(等待命令完成,如有必要). ... more stuff happens ... # if $bashcommand is done,this next line will execute right away # otherwise,it will wait until $bashcommand finishes ... print "Output of first command was ",$output; &do_something_with_command_output( $output1 ); @output2 = split /n/,$output2; ... 更新2012-03-01:vs.60 of Forks :: Super has some new constructions,可让您在列表上下文中检索结果: if ($condition) { tie @output,'Forks::Super::bg_qx',$bashcommand; tie @output1,$bashcommand1; tie @output2,$bashcommand2; tie @output3,$bashcommand3; } ... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 889. Construct Binary Tree from Preorder and Postorder
- delphi – 我会在异常处理之后释放/销毁异常吗?
- 如果Groovy列表按升序顺序排序,请按顺序排序和副Versa排序
- php – 需要在单个资源控制器中使用Entrust角色的建议 – L
- delphi – 如何链接包含WinAPI的C代码?
- 大数据处理思想
- Spring Boot:无法在类org.springframework.cloud.netflix.
- perl – 使用MooseX :: Declare关闭内联构造函数
- vb.net – MsgBox和MessageBox.Show有区别吗?
- 华为PTN910