#
# ELZAFORK fork for Win32.
#
# Usage
#
#	perl elzafork.pl NUMBER COMMANDFILE
#
# This script will fork NUMBER instances of elza, each running COMMANDFILE
#
# To find out how to fork under Unix, see elza.txt

# Set those according to your setup

$PathToPerl = 'c:\perl\bin\perl.exe';
$PathToElza = 'c:\elza\elza.pl';

# This means all processes will share the same console.

$ElzaFlags = 'common';

# Uncomment this if you want processes running in background.

#$ElzaFlags = 'background';

# Uncomment this if you want each process to have its own console.

#$ElzaFlags = 'separate';

# ======================================================================
# NO CHANGES BELOW THIS LINE ARE NECESSARY

use Win32::Process;

print "FRK ELZAFORK forking $ARGV[0] instances of ELZA.\n";

for $Counter (1..$ARGV[0]) {
	
	print "FRK Forking incarnation $Counter ... ";

	if ($ElzaFlags eq 'common') {
		Win32::Process::Create($FAKEOBJECT,$PathToPerl,"perl.exe $PathToElza $ARGV[1] $Counter $ARGV[0]",0, 0,'.') or die "FRK Unable to fork. Resource exhaustion?";
	}

	if ($ElzaFlags eq 'background') {
		Win32::Process::Create($FAKEOBJECT,$PathToPerl,"perl.exe $PathToElza $ARGV[1]",0, DETACHED_PROCESS,'.') or die "FRK Unable to fork. Resource exhaustion?";
	}

	if ($ElzaFlags eq 'separate') {
		Win32::Process::Create($FAKEOBJECT,$PathToPerl,"perl.exe $PathToElza $ARGV[1]",0, CREATE_NEW_CONSOLE ,'.') or die "FRK Unable to fork. Resource exhaustion?";
	}	
	print "Forked: $FAKEOBJECT\n";
}

print "FRK Forking completed.\n";