Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
windows上的并行perl系统调用_Perl - Fatal编程技术网

windows上的并行perl系统调用

windows上的并行perl系统调用,perl,Perl,试图找到一种方法让一个perl脚本在windows上运行另外4个perl脚本,然后在完成所有操作后,启动第5个脚本。我查了很多东西,但没有一件是直截了当的。欢迎提出建议。这些脚本将在windows设备上运行。在启动脚本5之前,脚本1-4需要先完成 接受其他问题的答案 使用线程 2.1。4个脚本的基调: my @scripts = qw(... commands ...); my @jobs = (); foreach my $script (@scripts) { my $job = thr

试图找到一种方法让一个perl脚本在windows上运行另外4个perl脚本,然后在完成所有操作后,启动第5个脚本。我查了很多东西,但没有一件是直截了当的。欢迎提出建议。这些脚本将在windows设备上运行。在启动脚本5之前,脚本1-4需要先完成

  • 接受其他问题的答案

  • 使用线程

    2.1。4个脚本的基调:

    my @scripts = qw(... commands ...);
    my @jobs = ();
    foreach my $script (@scripts) {
      my $job = threads->create( sub {
        system($script);
      });
      push @jobs, $job;
    }
    
    2.2。等待完成

    $_->join() foreach @jobs;
    
    2.3。开始最后一个脚本

  • 编辑 当你指出我的解决方案不适合你时,我启动了我的Windoze盒,教我使用这个可怕的cmd.exe并编写了以下测试脚本。与上述解决方案相比,它稍微简化了一些,但确实满足了您关于顺序性等方面的要求

    #!/usr/bin/perl
    use strict; use warnings; use threads;
    
    my @scripts = (
      q(echo "script 1 reporting"),
      q(perl -e "sleep 2; print qq{hi there! This is script 2 reporting\n}"),
      q(echo "script 3 reporting"),
    );
    
    my @jobs = map {
      threads->create(sub{
        system($_);
      });
    } @scripts;
    
    $_->join foreach @jobs;
    
    print "finished all my jobs\n";
    
    system q(echo "This is the last job");
    
    我使用此命令执行脚本(在Win7上,使用草莓Perl v5.12.2):

    这是输出:

    "script 1 reporting"
    "script 3 reporting"
    hi there! This is script 2 reporting
    finished all my jobs
    "This is the last job"
    

    那么,这究竟是怎么不起作用的呢?下次在非GNU系统上编写脚本时,我非常想学习如何绕过Perl的陷阱,因此请告诉我可能出现的错误。

    根据个人经验,在ActiveState中使用
    fork()
    ,Perl并不总是按顺序运行进程。这里使用的
    fork()
    的线程模拟似乎启动了所有进程,将其运行到某一点,然后一次运行一个进程。这甚至适用于多核CPU。我认为草莓Perl也是以同样的方式编译的。另外,请记住,
    fork()
    仍被用于反勾号,而
    system()
    ,它只是抽象出来的


    如果在Windows上使用Cygwin Perl,它将通过Cygwin自己的
    fork()
    调用运行,事情将正确地并行化。但是,Cygwin在其他方面速度较慢。

    调度由操作系统完成,而不是由Perl完成。是的,ActiveState和草莓使用相同的模拟。@ikegami:效果从何而来并不重要——这是一个需要注意的问题。这不起作用,但谢谢。我不知道你在说什么,接受答案。我问过的大多数问题都没有答案,或者答案对我不适用。我将更积极地响应所提供的帮助,并接受有效的答案。@user1279586很抱歉听到这个消息,很遗憾我无法帮助您使用Ruby…好吧,我的代码对我来说很有效,Perl应该隐藏这样一个事实,即我们正在使用不同的操作系统和如此简单的脚本。我写了一个Windoze测试,效果很好。你能比较一下你的结果吗?
    use Proc::Background;
    
    my @commands = (
      ['./Files1.exe ALL'],
      ['./Files2.exe ALL'],
      ['./Files3.exe ALL'],
      ['./Files4.exe ALL'],
    ); 
    
    my @procs = map {  Proc::Background->new(@$_) } @commands;
    
    $_->wait for @procs;
    
    system 'echo', 'CSCProc', '--pidsAndExitStatus', map { $_->pid, $_->wait } @procs;
    
    `mergefiles.exe`;
    
    use Proc::Background;
    
    my @commands = (
      ['./Files1.exe ALL'],
      ['./Files2.exe ALL'],
      ['./Files3.exe ALL'],
      ['./Files4.exe ALL'],
    ); 
    
    my @procs = map {  Proc::Background->new(@$_) } @commands;
    
    $_->wait for @procs;
    
    system 'echo', 'CSCProc', '--pidsAndExitStatus', map { $_->pid, $_->wait } @procs;
    
    `mergefiles.exe`;