我在Windows操作系统上使用了5.14.2版本的perl。我不知道我在哪里做错了。请给出一些建议:
package qpst_dump_collection;
use strict;
use warnings;
no warnings qw(once);
use Win32::OLE::Variant;
our $folder;
my $collectDumpsSuccess =1;
my $currentDir = 'c:';
chomp($currentDir);
my $logsPath;
my $timestamp;
our @Month_name;
my $sec;
my $min;
my $hour;
my $day;
my $month;
my $year;
my $comport;
my $comportBool = 0;
my $testcase;
$timestamp = getTimeStamp();
our $DLModem;
our $dev_id;
sub CollectDumpsIfDeviceinDownloadMode
{
sleep 20;
$testcase = $ARGV[0];
$comport = $ARGV[1];
#$currentDir =~ s/\\/\//g;
$timestamp = getTimeStamp();
$logsPath = $currentDir. "/Logs";
print "\n**************** loc is $logsPath *************************\n";
my $prod_id = "QPSTAtmnServer.Application";
my $qpst;
my $dirpath = $testcase."_"."QPSTDumps"."_".$timestamp;
my $LogLocationPath = $logsPath."/$dirpath";
#my $LogLocationPath = $logsPath."/QPSTDumps_$timestamp";
my $accum = "";
my $dir;
# Recursively create directories
foreach $dir (split(/\//, $logsPath))
{
$accum = "$accum$dir/";
if ($dir ne "")
{
if(! -d "$accum")
{
mkdir $accum or print "Unable to create directory: $accum\n";
}
}
}
if(`adb -s $dev_id get-state` !~ m/device/i){
print "Dumps will be stored at $LogLocationPath.................\n";
sleep 10;
# Attempt to use a running instance.
eval
{
$qpst = Win32::OLE->GetActiveObject($prod_id)
};
die "$prod_id not installed" if $@;
# Start a new instance. Call Quit when $qpst set to undef or script exits.
unless (defined $qpst)
{
$qpst = Win32::OLE->new($prod_id, sub {$_[0]->Quit;}) or die "Oops, cannot start $prod_id";
}
if (defined $qpst)
{
my $port = undef;
#my $comport = "COM44";
if ($comport eq "")
{
$qpst->ShowWindow();
print "Select a phone on the GUI,\nthen return to this window and press enter to continue";
<STDIN>;
$port = $qpst->GetSelectedPort();
}
$port = $qpst->GetPort($comport);
# Translate phone status to string.
my %phone_status_list = qw (
0 phoneStatusNone
5 phoneStatusReady) ;
if (defined $port)
{
$comport = $port->PortName;
sleep(5);
my $port_status = $port->PhoneStatus;
if ($phone_status_list{$port_status} eq "phoneStatusReady")
{
my $memory_debug = $port->MemoryDebug;
if (defined $memory_debug)
{
if (!-e $LogLocationPath)
{
mkdir $LogLocationPath;
}
print "Attempting to collect dumps -- usually takes 1-3 minutes...........\n";
$memory_debug->{UseUnframedMemoryRead} = 1; # boolean to tell QPST to use higher speed unframed memory reads
$memory_debug->SaveAllRegions($LogLocationPath);
if (Win32::OLE->LastError == 0)
{
print "Dumps collected successfully..........\n";
$collectDumpsSuccess = 1;
print "Rebooting device to prepare for next iteration. Please wait 60 seconds........\n";
$port->Reset();
sleep(60);
}
else
{
my $error = Win32::OLE->LastError();
print "Dumps were not collected successfully:\n$error\n";
}
}
else
{
print "No MemoryDebug interface for this port\n";
}
undef $memory_debug;
}
else
{
print "Phone not ready\n";
CollectDumpsIfDeviceinDownloadMode_auto();
}
}
else
{
print "Port not available_1\n";
CollectDumpsIfDeviceinDownloadMode_auto();
}
undef $port;
}
else
{
print "QPST not available\n";
}
undef $qpst;
}
else{
print "Device detected in adb...";
$collectDumpsSuccess = 1;
}
}
sub CollectDumpsIfDeviceinDownloadMode_auto
{
sleep 20;
#$currentDir =~ s/\\/\//g;
$timestamp = getTimeStamp();
$logsPath = $currentDir. "/Logs";
print "\n**************** loc is $logsPath *************************\n";
my $prod_id = "QPSTAtmnServer.Application";
my $qpst;
my $dirpath = $testcase."_"."QPSTDumps"."_".$timestamp;
my $LogLocationPath = $logsPath."/$dirpath";
#my $LogLocationPath = $logsPath."/QPSTDumps_$timestamp";
my $accum = "";
my $dir;
# Recursively create directories
foreach $dir (split(/\//, $logsPath))
{
$accum = "$accum$dir/";
if ($dir ne "")
{
if(! -d "$accum")
{
mkdir $accum or print "Unable to create directory: $accum\n";
}
}
}
if(`adb -s $dev_id get-state` !~ m/device/i){
print "Dumps will be stored at $LogLocationPath.................\n";
sleep 10;
# Attempt to use a running instance.
eval
{
$qpst = Win32::OLE->GetActiveObject($prod_id)
};
die "$prod_id not installed" if $@;
# Start a new instance. Call Quit when $qpst set to undef or script exits.
unless (defined $qpst)
{
$qpst = Win32::OLE->new($prod_id, sub {$_[0]->Quit;}) or die "Oops, cannot start $prod_id";
}
if (defined $qpst)
{
my $port = undef;
#my $comport = "COM44";
my $portList = $qpst->GetPortList();
print(" portList : $portList \n");
my $numports = $portList->PhoneCount;
print(" numports : $numports \n");
for my $index (0..$numports-1) {
my $vindex = Variant(VT_I2, $index);
my $portname = $portList->PortName ($vindex);
my $mode = $portList->PhoneMode ($vindex);
print(" vindex : $vindex \n");
print(" portname : $portname \n");
print(" mode : $mode \n");
if ($mode == 2) { # 4 for modeDownload, 3 for online
print "**************Connected to COMPORT *************************\n";
$comport = $portname;
print(" comport : $comport \n");
}
}
if ($comport eq "")
{
$qpst->ShowWindow();
print "Select a phone on the GUI,\nthen return to this window and press enter to continue";
<STDIN>;
$port = $qpst->GetSelectedPort();
}
$port = $qpst->GetPort($comport);
# Translate phone status to string.
my %phone_status_list = qw (
0 phoneStatusNone
5 phoneStatusReady) ;
if (defined $port)
{
$comport = $port->PortName;
sleep(5);
my $port_status = $port->PhoneStatus;
if ($phone_status_list{$port_status} eq "phoneStatusReady")
{
my $memory_debug = $port->MemoryDebug;
if (defined $memory_debug)
{
if (!-e $LogLocationPath)
{
mkdir $LogLocationPath;
}
print "Attempting to collect dumps -- usually takes 1-3 minutes...........\n";
$memory_debug->{UseUnframedMemoryRead} = 1; # boolean to tell QPST to use higher speed unframed memory reads
$memory_debug->SaveAllRegions($LogLocationPath);
if (Win32::OLE->LastError == 0)
{
print "Dumps collected successfully..........\n";
$collectDumpsSuccess = 1;
print "Rebooting device to prepare for next iteration. Please wait 60 seconds........\n";
$port->Reset();
sleep(60);
}
else
{
my $error = Win32::OLE->LastError();
print "Dumps were not collected successfully:\n$error\n";
}
}
else
{
print "No MemoryDebug interface for this port\n";
}
undef $memory_debug;
}
else
{
print "Phone not ready\n";
}
}
else
{
print "Port not available_2\n";
}
undef $port;
}
else
{
print "QPST not available\n";
}
undef $qpst;
}
else{
print "Device detected in adb...";
$collectDumpsSuccess = 1;
}
}
sub getTimeStamp
{
@Month_name = ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" );
($sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2, 3, 4, 5 ];
$timestamp = @Month_name->[$month]."-".$day."---".$hour.".".$min.".".$sec;
return $timestamp;
}
1;
答案 0 :(得分:4)
这可能是您的错误:
@Month_name->[$month]
应该是:
$Month_name[$month]