perl - perl 中的 xargs 等价物

标签 perl shell exec fork xargs

我喜欢做一些东西,就像 shellscripting 中的 xargs 所做的那样。因此:

  1. 通过exec() 系统调用运行外部命令
  2. 作为子进程
  3. 并行
  4. 等待执行(最好有超时)

如何在 perl 中完成?

最佳答案

您可以使用 Proc::Background 模块。 特别有趣的是子 timeout_system(..)

这是来自 Proc::Background 的示例模块页面:

use Proc::Background;
timeout_system($seconds, $command, $arg1);
timeout_system($seconds, "$command $arg1");

my $proc1 = Proc::Background->new($command, $arg1, $arg2);
my $proc2 = Proc::Background->new("$command $arg1 1>&2");
$proc1->alive;
$proc1->die;
$proc1->wait;
my $time1 = $proc1->start_time;
my $time2 = $proc1->end_time;

# Add an option to kill the process with die when the variable is
# DETROYed.
my $opts  = {'die_upon_destroy' => 1};
my $proc3 = Proc::Background->new($opts, $command, $arg1, $arg2);
$proc3    = undef;

关于perl - perl 中的 xargs 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23363301/

相关文章:

c - 为什么调用 execvp 时此 free 会失败?

python - 将 PyPy 编译为 Exe

Perl unless 散列声明中的语句 - 这可能吗?

shell - 进行键绑定(bind)以运行上一个或最后一个 shell 命令

java - 将 sshpass 与 bash 一起使用可以从命令行运行,而不是从 java exec 运行

linux - 从 Mac iOS 到 Linux

shell - 应用程序和 shell 之间的区别

c++ - 如何在 Makefile.PL 中检查 C++ 编译器?

perl - 我在这个 Perl 代码中犯了什么错误?

用于符号链接(symbolic link)的 Cwd::abs_path 的 Perl 替代方案