【问题标题】:How to check output from command - PERL [closed]如何检查命令的输出 - PERL [关闭]
【发布时间】:2014-10-23 09:28:15
【问题描述】:

我有一个问题,我是 Perl 的新手,所以。 我想从我发送的命令中获取输出以检查它是否完成,例如:

在我的模块中,我运行命令 my_zip_command file a_lot_of_file',我希望我的模块等到消息“所有文件都正确压缩”才会打印出来。

我尝试获取 STDOUT,但它对我不起作用,或者我只是做错了。

bash>my_zip_command file a_lot_of_file
>ziping file1 100%
>ziping file2 100%
>ziping file3 100%
>all file were zip correctly
bash>

感谢大家的帮助

【问题讨论】:

  • What have you tried? SO 不是一个为我写一些代码的网站。您必须自己尝试,当您被困在某个地方时,请在此处说明您的问题,您将获得帮助。

标签: perl output stdout


【解决方案1】:

如果你正在尝试

  1. 从您的 perl 脚本运行命令并
  2. 在 perl 脚本中捕获该命令的输出

这是我能想到的最简单的方法。

my @output = `my_zip_command file a_lot_of_file`;

@output 将保存命令的完整输出。

【讨论】:

  • 还要检查 $? 是否有零退出代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-17
  • 1970-01-01
  • 2016-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-14
相关资源
最近更新 更多