Previous Topic: PerlScript Example: WinGetInfoPerl Script OperatorNext Topic: Process Parameters


Script (PerlScript)

The script creates two indexed fields, HostList and OSList in the WinGetInfoPerl operator dataset. The script:

The script populates the ARGV variable with the Parameters input area entries of the calling Run Script operator. The script assigns the number of rows it reads to the NumRowsRead operator dataset variable. The sleep 30 line pauses the operator for 30 seconds so the user can examine the folders and files created in the C2OSVD location. You would not include the sleep 30 line in a production script.

use strict;
my $filename = "";
print "  sample script to retrieve OS level data into variables within C2O\n\n";
my $numargs = @ARGV;
if ($numargs == 1) {
$filename = shift @ARGV;
} else {
print "enter path and filename to process:\n";
chomp($filename = <STDIN>);
}
my $c2osvd = $ENV{'C2OSVD'};
mkdir $c2osvd;
mkdir $c2osvd . "/HostList";
mkdir $c2osvd . "/OSList";
open HANDLE, $filename or die "ERROR: unable to open $filename: $!\n";
my $counter = 0;
while (<HANDLE>) {
my @fields = split;
my $host = $fields[0];
my $opsys = $fields[1];
my $filename1 = $c2osvd . "/HostList/" . $counter;
open HH, "> $filename1" or die "ERROR: unable to open $filename1: $!\n";
print HH $host;
close HH;
my $filename2 = $c2osvd . "/OSList/" . $counter;
open HH, "> $filename2" or die "ERROR: unable to open $filename2: $!\n";
print HH $opsys;
close HH;
$counter++;
}
my $filename3 = $c2osvd . "/NumRowsRead";
open HH, "> $filename3" or die "ERROR: unable to open $filename3: $!\n";
print HH $counter;
close HH;
close HANDLE;
sleep 30;