Problem with Win32::Service in sub

2005-12-06 Thread Denis Peuziat

Hi,

I'm a newbie with perl and I don't know much about programming either. I
wrote a script to manipulate services on Windows, and it works fine :

use Win32::Service;
$server_main=ncedpeuziat;
$server_backup=nceoatestdp;
$current_date = localtime(time);

open(LOGFILE, CServer_Sync.log);
print LOGFILE TEST LOG\n\n;
print LOGFILE
***\n;
print LOGFILE
***\n;
print LOGFILE \nTEST was started on: ;
print LOGFILE $current_date\n;

print LOGFILE Stopping SNMP on $server_backup...\n;
Win32::Service::StopService($server_backup, 'SNMP');
sleep(5);
Win32::Service::GetStatus($server_backup, 'SNMP', \%status);
$Service_Status= $status{CurrentState};
if ($Service_Status == 1) {
  print LOGFILE SNMP service successfully stopped on
$server_backup\n;
} else {
sleep(5);
Win32::Service::GetStatus($server_backup, 'SNMP', \%status);
$Service_Status= $status{CurrentState};
if ($Service_Status != 1) {
  print LOGFILE ERROR: SNMP service cannot be stopped on
$server_backup\n;
  close(LOGFILE);
  exit;
}
print LOGFILE SNMP service successfully stopped on $server_backup\n;
  }

And I have to do this with a couple of services so I thought I might as
well write a function to do it, and that's where the pb starts:

use Win32::Service;
$server_main=ncedpeuziat;
$server_backup=nceoatestdp;
$current_date = localtime(time);

open(LOGFILE, CServer_Sync.log);
print LOGFILE TEST LOG\n\n;
print LOGFILE
***\n;
print LOGFILE
***\n;
print LOGFILE \nTEST was started on: ;
print LOGFILE $current_date\n;

Stop_Service(SNMP,$server_backup);

sub Stop_Service {
print LOGFILE Stopping $_[0] on $_[1] ...\n;
Win32::Service::StopService($_[1], '$_[0]');
sleep(5);
Win32::Service::GetStatus($_[1], '$_[0]', \%status);
$Service_Status=$status{CurrentState};
if ($Service_Status == 1) {
  print LOGFILE $_[0] service successfully stopped on $_[1]\n;
} else {
sleep(5);
$Service_Status=Win32::Service::GetStatus($_[1], '$_[0]', \%status);
if ($Service_Status != 1) {
  print LOGFILE ERROR: $_[0] service cannot be stopped on $_[1]\n;
  close(LOGFILE);
  exit;
}
print LOGFILE $_[0] service successfully stopped on $_[1]\n;
  }
}

I tried to log steps and it seems that the sub cannot interpret the win32
commands

Any help would be welcome

Thanks

Denis

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Forced interpolation

2005-12-06 Thread Артем Аветисян
Hi, all.

use strict;
my $str = 'lazha';
my $pattern = 'la(zh)(a)';
my $replacement = '$1op$2';

$str =~ s/$pattern/$replacement/;
print $str;
__END__

I want

zhopa

to be printed. So far it is obviously '$1op$2'. eval (as well as s///ee) 
doesn't seem to be helpful.
More generally, I want to know if there is a way to interpolate variables in a 
single quoted string (or possibly change the quotation before?) at any moment.

Thanks,
Artem A. Avetisyan.

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Problem with Win32::Service in sub

2005-12-06 Thread Reinhard Pagitsch



Denis Peuziat wrote:


Hi,

I'm a newbie with perl and I don't know much about programming either. I
wrote a script to manipulate services on Windows, and it works fine :


sub Stop_Service {
print LOGFILE Stopping $_[0] on $_[1] ...\n;
Win32::Service::StopService($_[1], '$_[0]');
 


That shall be:
Win32::Service::StopService($_[1], $_[0]);


sleep(5);
Win32::Service::GetStatus($_[1], '$_[0]', \%status);
 


And that shall be:
Win32::Service::GetStatus($_[1], $_[0], \%status);

What you  are doing in your orignial code is to pass the string $_[0] to 
GetStatus and StopService,

and not the value of $_[0].

regards,
Reinhard
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Forced interpolation

2005-12-06 Thread Charles K. Clarkson
Àðòåì Àâåòèñÿí  wrote:

: use strict;
: my $str = 'lazha';
: my $pattern = 'la(zh)(a)';
: my $replacement = '$1op$2';
: $str =~ s/$pattern/$replacement/;
: print $str;
: __END__
:
: I want
:
: zhopa

my $replacement = $1o\p$2;

# or:

my $replacement = qq($1op$2); # You can read more about qq() in perlop.


: More generally, I want to know if there is a way to interpolate
: variables in a single quoted string

No.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

 . . . With Liberty and Justice for all (heterosexuals).


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Forced interpolation

2005-12-06 Thread Chris Wagner
At 06:47 PM 12/6/2005 +0300, 
my $str = 'lazha';
my $pattern = 'la(zh)(a)';
my $replacement = '$1op$2';
$str =~ s/$pattern/$replacement/;
print $str;
I want zhopa to be printed. So far it is obviously '$1op$2'. eval (as well 

I think ur going about this the wrong way.  I'm guessing that u want to
first search for the pattern, and then substitute based on anything it found.

$str = 'lazha';
$pattern = qr/la(zh)(a)/;
$str =~ m/$pattern/;
if ($1 and $2) {
$replacement = $1o\p$2;
$str =~ s/$pattern/$replacement/;
}
print $str\n;
##
zhopa

Or as a one-liner:
$str =~ s/la(zh)(a)/$1op$2/;   # same thing

Excessive way:
$str = 'lazha';
$pattern = qr/la(zh)(a)/;

$str =~ s/$pattern/rep($1,$2)/e;
print $str\n;

sub rep {
return $_[0]o\p$_[1];
}











--
REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =--
...ne cede malis

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Forced interpolation

2005-12-06 Thread Craig Cardimon
I wanted to make a joke about the subject, but every time I try such a 
thing, it never comes out right. Sigh.


-- Craig


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0549-2, 12/06/2005
Tested on: 12/6/2005 12:54:08 PM
avast! - copyright (c) 1988-2004 ALWIL Software.
http://www.avast.com




___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re[2]: Forced interpolation

2005-12-06 Thread Артем Аветисян
Wow.. I thought about evaling $replacement only, but this way.. It works 
great. Except it is a brain damage (for me) to understand why it works ;)

This trick with \$str in eval is really worth a record in Cookbook.

The actual task which caused the issue is that parts of regexp are given be a 
user in GUI, but regexp itself is executed later in the program. So i needed a 
general way of handling $replacement like things.

Thanks a lot,
Artem A. Avetisyan.

 
 
 Hi
 
 I try with qr//, but found nothing good,
 but eval work well
 
 my $str = 'lazha';
 my $pattern = 'la(zh)(a)';
 my $replacement = '$1op$2';
 eval \$str =~ s/$pattern/$replacement/;;
 print$str;
 __END__
 zhopa
 - Original Message - 
 From: Артем Аветисян [EMAIL PROTECTED]
 To: perl-win32-users@listserv.ActiveState.com
 Sent: Tuesday, December 06, 2005 4:47 PM
 Subject: Forced interpolation
 
 
  Hi, all.
 
  use strict;
  my $str = 'lazha';
  my $pattern = 'la(zh)(a)';
  my $replacement = '$1op$2';
 
  $str =~ s/$pattern/$replacement/;
  print $str;
  __END__
 
  I want
 
  zhopa
 
  to be printed. So far it is obviously '$1op$2'. eval (as well as s///ee)
 doesn't seem to be helpful.
  More generally, I want to know if there is a way to interpolate variables
 in a single quoted string (or possibly change the quotation before?) at any
 moment.
 
  Thanks,
  Artem A. Avetisyan.
 
  ___
  Perl-Win32-Users mailing list
  Perl-Win32-Users@listserv.ActiveState.com
  To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
 
 
 This message contains information that may be privileged or confidential and 
 is the property of the Capgemini Group. It is intended only for the person to 
 whom it is addressed. If you are not the intended recipient,  you are not 
 authorized to read, print, retain, copy, disseminate,  distribute, or use 
 this message or any part thereof. If you receive this  message in error, 
 please notify the sender immediately and delete all  copies of this message.
 

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re[2]: Forced interpolation

2005-12-06 Thread Артем Аветисян
English is not my native, so i'd be pleased if you explain me the point :)

 
 I wanted to make a joke about the subject, but every time I try such a 
 thing, it never comes out right. Sigh.
 
 -- Craig
 
 
 ---
 avast! Antivirus: Outbound message clean.
 Virus Database (VPS): 0549-2, 12/06/2005
 Tested on: 12/6/2005 12:54:08 PM
 avast! - copyright (c) 1988-2004 ALWIL Software.
 http://www.avast.com
 
 
 
 

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Forced interpolation

2005-12-06 Thread $Bill Luebkert
Артем Аветисян wrote:

 English is not my native, so i'd be pleased if you explain me the point :)

He probably had in mind something of a sexual nature.  :)

I wanted to make a joke about the subject, but every time I try such a 
thing, it never comes out right. Sigh.
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


using Win32::OLE to copy or copy a range from one sheet to another

2005-12-06 Thread Glen Plantz
Title: Message



Hi 
Folks,

I've been using Perl 
for a number of years, and I'm now learning Win32::OLE for manipulating Excel 
files. I'm try to copyor cut a range of cells from one Worksheet to 
another. The "Select" portion works fine, but the "Paste" is not 
working..

Thanks in advance 
for any help. 

Glen 
Plantz
Mitchell 
International

[EMAIL PROTECTED]



Here is my 
code:


  my $excel_app = 
  Win32::OLE-new('Excel.Application')or die "could not create excel 
  app\n";
  
  $excel_app-{'Visible'} = 1;
  $excel_app-{ 
  'SheetsInNewWorkbook' } = 1;
  
  my $excel_Workbook 
  = $excel_app-Workbooks-Open($Excel_CSAA_Test_Retrieve )or die 
  "could not open $Excel_CurrentMonth_Retrieve\n";
  
  # this section 
  executes VBA functions in the Workbook opened above to retrieve data from an 
  Hyperion Essbase database... this works fine
   
  $excel_app-RegisterXLL($Essbase_Addin_loc);
   
  $excel_app-{ 'DisplayAlerts' } = 0;
  
   
  my $excel_Workbook = 
  $excel_app-Workbooks-Open($Excel_CSAA_Test_Retrieve 
  ) or die "could not open 
  $Excel_CurrentMonth_Retrieve\n"; my $m_sVBAFunctionName 
  = "'" . $Excel_CSAA_Test_Retrieve . "'!Connect";
   
  my $retVal = $excel_app-Run($m_sVBAFunctionName, $Essbase_Server, 
  $Essbase_UserID, $Essbase_Password, $Essbase_Application, 
  $Essbase_Database); print "retVal = 
  $retVal\n"; $m_sVBAFunctionName = "'" . 
  $Excel_CSAA_Test_Retrieve . "'!Retrieve";
  
   
  $retVal = $excel_app-Run($m_sVBAFunctionName);
  # END - Data Retrieve
  
   print 
  "retVal = $retVal\n";

  my $Sheet1 = 
  $excel_Workbook-Worksheets(1);
  
  $Sheet1-Range("A29:P39")-Select()$Sheet1-Range("A29:P39")-Copy();

  my $Sheet = 
  $excel_Workbook-Worksheets-Add({After=$excel_Workbook-Worksheets($excel_Workbook-Worksheets-{Count})}) 
  or die Win32::OLE-LastError();
  $Sheet-{Name} = "Glens"
  
  
  $ works fine up to year,... the "Sheet1" 
  excel sheet above shows that the range "A29:P39" has been selected and 
  copied
  
  # 
   Here is 
  where I'm running into trouble this Paste is not 
  working...
  
  $Sheet-Range("A29")-Paste();
  
  
  
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Forced interpolation

2005-12-06 Thread Chris Wagner
At 01:10 PM 12/6/2005 -0800, $Bill Luebkert wrote:
Артем Аветисян wrote:

 English is not my native, so i'd be pleased if you explain me the point :)

He probably had in mind something of a sexual nature.  :)

I wanted to make a joke about the subject, but every time I try such a 
thing, it never comes out right. Sigh.


I always thought the fork() function should have a companion spoon()
function.  But u have to be careful with that, because spooning can lead to
forking.





--
REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =--
...ne cede malis

0100

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


David Wright/sail-technology is out of the office

2005-12-06 Thread David . Wright
I will be out of the office starting  05/12/2005 and will not return until
30/12/2005.

Technical Support is available at
[EMAIL PROTECTED]

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: using Win32::OLE to copy or copy a range from one sheet to another

2005-12-06 Thread Allegakoen, Justin Devanandan
---8---
I've been using Perl for a number of years, 
---8---
And you post code with no use strict and warnings? :p

Actually what you posted fails to run. So I tidied it up a bit and got
this to copy and paste as you desired. Do allow for line wrap.

CODE
use strict;
use warnings;
# Don't need these, but good to load as your code gets bigger
use Win32::OLE qw(in with); 
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Variant;
$Win32::OLE::Warn = 3;

my $Excel_CSAA_Test_Retrieve = 'C:\Temp\Temp.xls';
my $excel_app = Win32::OLE-new('Excel.Application')
or die could not create excel app\n;
 
$excel_app-{'Visible'} = 1;
$excel_app-{ 'SheetsInNewWorkbook' }  = 1;
 
my $excel_Workbook =
$excel_app-Workbooks-Open($Excel_CSAA_Test_Retrieve ) or die could
not open $Excel_CSAA_Test_Retrieve:- $! \n;
my $Sheet1 = $excel_Workbook-Worksheets(1);
 
# I dont have your VBA function
# In your posting you declared $excel_Workbook before the next variable
declaration so I got an error
# I also got errors about unterminated lines
# Bottom line is your code as posted does not run with strict and
warnings enabled
foreach my $Col('A' .. 'Q')
{
foreach my $Row(1 .. 40)
{
$Sheet1-Range($Col$Row)-{Value} = int(rand($Row));
}
}
 
$Sheet1-Range(A29:P39)-Select();
$Sheet1-Range(A29:P39)-Copy();
my $Sheet =
$excel_Workbook-Worksheets-Add({After=$excel_Workbook-Worksheets($ex
cel_Workbook-Worksheets-{Count})}) or die Win32::OLE-LastError();
$Sheet-{Name} = Glens;
my $GlensSheet = $excel_Workbook-Worksheets(Glens);
 
$GlensSheet-Range(A29)-Select();
$GlensSheet-Paste()
/CODE

Cheers,
Just in

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs