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

Hi Monks!
I have written a small programme to execute "rsh" command with time out option. Here is my code.
use strict; my $NETE_FAILURE = -1; my $NETE_SUCCESS = 0; my $timeout = 10; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; my $Error = &Rsh("<machinename>","perl <path>s1.pl"); print "Error::$Error\n"; if ($Error == $NETE_FAILURE) { die "Failure\n"; } alarm 0; }; if ($@) { if ($@ eq "alarm\n") { die "TimeOut\n"; } } else { print "Success\n"; } sub Rsh { my($MachineName,$Command,$ErrorText,$Length); if (scalar(@_) != 2) { print ("Error:Wrong number of arguments supplied\n"); return ($NETE_FAILURE); } ($MachineName,$Command)=@_; # Get the machine OS my $OS=$^O; if ($OS=~ m/hpux/i) { $Command = "remsh" . " $MachineName" . " $Command"; } elsif ($OS =~ /MSWin32/i) { $Command = "rsh" . " $MachineName" . " -n $Command"; } else { $Command = "rsh" . " $MachineName" . " $Command"; } #Creating temporary file my $ErrorFile = "RH".$$; my $Error = 0xffff & system("($Command 2>$ErrorFile)"); # Open the error file and see if it has some contents if( open (fhError, "< $ErrorFile")) { while (<fhError>) { $ErrorText .= $_; } $Length = scalar(split(//,$ErrorText)); if($Length != 0 ) { print ("Error:$ErrorText"); close (fhError); unlink ($ErrorFile); return ($NETE_FAILURE); } else { close (fhError); } } unlink ($ErrorFile); if ($Error != 0 ) { print ("Error:Executed command $Command with error return status +\n"); return ($NETE_FAILURE); } return ($NETE_SUCCESS); }
This is running fine in Solaris box but when I am trying to execute in Windows 2000 box then Rsh function within eval block is not executing. Any pointer how can I execute Rsh function in Win2k box?
Thanks in advance.
Regards
-Pijush

Replies are listed 'Best First'.
Re: How can I execute "eval" command in WINDOWS 2000? (alarm)
by tye (Sage) on Jan 12, 2004 at 17:24 UTC

    You need an else { die $@ } for your if ($@ eq "alarm\n") and you'd see that calling alarm on Win32 gives:

    The Unsupported function alarm function is unimplemented at
    which prevents the rest of the evaled block from running.

                    - tye
      But alarm does work on ActivePerl 5.8.x (tested with ActivePerl 5.8.0, Build 804), by contrast to 5.6.1 and earlier.
        According to your suggestion I have upgraded perl from v5.61. to v5.8.2 build 808 to get alarm function. But now I am facing a different problem. In my perl script I used win32-setupsup module to install a GUI based software and after installion completed, machine is rebooted and this reboot is the forceful reboot as the perl script is running. In v5.6.1 this is running fine but when I am testing with v5.8.2 then in the rebooting time I am getting an error which is telling thet failed to terminate programme and the execution of script is stopped at that point. Any pointer how can I resolve this problem.
        Thanks in advance.
        Regards
        -Pijush
      yes. you are right. I put two print statement before and after alarm call and it printed the print statement which is before the alarm call. Can you suggest how can I execute the programme successfully?
      TIA
      -Pijush
Re: How can I execute "eval" command in WINDOWS 2000?
by Abigail-II (Bishop) on Jan 12, 2004 at 17:02 UTC
    What makes you think the function isn't executed? It shoulds quite unbelievalbe that Perl just skips a function call on a particular platform.

    Abigail

      I also surprised when I found out that it skips the eval block. To check, I have written a piece of code to create one file C:\\Temp.out in the first line within eval block and write something in it. But that file also not created. Is it the right approach? Or how can I check? I have also tried with print statement within eval block but that also not working.
      TIA
      -Pijush
        Anything in $@ ?

        Abigail