John V. Pataki wrote:
> I need to run my perl program as a clone because I am
> calling it from within another application that intend
> to talk back to. The application's execute command
> wants to wait until the call to perl program is
> finished before continuing.
>
> I had this working at one time and now it seems to not
> work ( I dredged up some old code from an older
> project ). I think it is actually running a new
> version of the program but it is not accepting a value
> I pass it to test whether it is really a clone or not.
>
>
> Here is what I have (that used to work at one time):
>
> BEGIN {
> if ($ARGV[0] !~ /^-/) {
> if ($^O =~ /MSWin32/i) {
> if ($ARGV[0] ne "clone") {
> exec("$0 clone @ARGV") or die "Couldn't clone
> myself. $!\n";
> } # end if
> if ($ARGV[0] eq "clone") {print "CLONED!\n";shift
> @ARGV};
> } # end if
> else {
> if ($pid = fork) {sleep 1;exit;};
> if (! defined $pid) {die "Couldn't clone myself.
> $!\n"};
> } # end else
> } # end if
> } # end block
>
>
>
> I am not getting the message that it couldn't clone
> itself - I am just getting continously re-starting of
> the program ... so that tells me the pseudo-clone is
> working but my test is failing...
>
> Any clues on what I am missing?
fork should work on later versions of Win32 (at least kinda).
Try soimething like this for a test :
use strict;
my $pid = fork;
die "fork failed: $!" if not defined $pid;
if ($pid == 0) {
print "I am the clone\n";
print "[EMAIL PROTECTED]";
sleep 10;
exit 99;
} else {
print "I cloned $pid\n";
print "[EMAIL PROTECTED]";
waitpid $pid, 0;
print "Clone returned $?\n";
}
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs