Reputation: 7
I wrote this code that should open several process , the problem is its work on linux well but when i execute it on windows its just create one process !!. is this possible to create multiprocess on windows with perl ?
$j = ARGV[0];
for($i=1; $i<=$j; $i++){
system("perl example.pl word.txt.$i &");
}
Upvotes: 0
Views: 801
Reputation: 37136
&
is a *nix thing. An explicit fork
in Windows will do it.
Bear in mind that Windows implementations of Perl emulate forking using threads, so that may be another option.
my @pids;
for my $i (1 .. $j) {
my $pid = fork;
unless ( $pid ) { # Child
system("perl example.pl word.txt.$i");
exit 0;
}
push @pids, $pid;
}
waitpid $_, 0 foreach @pids;
Upvotes: 6
Reputation: 1285
It is a lot easier to use the START command (Windows Batch command) than to fork processes. The downside is that it will open multiple DOS windows.
system "start perl example.pl word.txt.$i";
Upvotes: 0
Reputation: 43498
Better fork
from the enclosing Perl script and then call system
in the child process without the trailing &
. wait
will be needed in the parent as well.
Because the argument of system
is parsed by the system shell, you will encounter different behaviour from the Windows shell than from Bash, for example.
Upvotes: 3