Discipulus has asked for the wisdom of the Perl Monks concerning the following question:

Gretings dear monks!!

I was re-using the code getservertype2.pl by some monk here around, on a w2k activeperl 5.8 to get the output of system call via rcmd of several machines.
The code never print "Parent exiting...\n" WHY ??(the original code print it)
I have to put the line sleep 1 in the sub 'cause the script was not waiting for all the pseudo-process
I never experimented forks 'cause i'm forced to work on w2k so maybe i'm doing some trivial error
#!/usr/bin/perl -w use strict; $|=1; my @ip qw (192.168.0.1 192.168.0.2 192.168.0.3) my $kid; foreach my $host(@ip) { next if $kid = fork; die "fork: $!" unless defined $kid; & doit ($host); exit; } 1 while wait != -1; print "Parent exiting...\n"; exit; sub doit { my $server = shift; open RCMD, "rcmd \\\\$server ipconfig|"; while (<RCMD>){if ($_=~/Executing/){print "$_\n";}} close RCMD; sleep 1; }
greetings from roma Lor*

Replies are listed 'Best First'.
Re: 1 while wait != -1; on w2k
by tachyon (Chancellor) on Mar 11, 2004 at 13:41 UTC

    It looks like your &doit routine is not returning. On win2k this works fine (once you fix your typos so it will compile :o)

    C:\>type test.pl #!/usr/bin/perl -w use strict; $|=1; my @ip = qw (192.168.0.1 192.168.0.2 192.168.0.3); my $kid; foreach my $host(@ip) { next if $kid = fork; die "fork: $!" unless defined $kid; & doit($host); exit; } 1 while wait != -1; print "Parent exiting...\n"; exit; sub doit { my $server = shift; print "Doin it to $server, stand clear of the doors please!\n"; } C:\>perl test.pl Doin it to 192.168.0.1, stand clear of the doors please! Doin it to 192.168.0.2, stand clear of the doors please! Doin it to 192.168.0.3, stand clear of the doors please! Parent exiting... C:\>

    Add some debugging print statements so you can see WHERE it is hanging.

    cheers

    tachyon