By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

Starting and stopping service

P: 15
Hi Perl Experts,

Is there any inbuilt sys functions which can start and stop a tomcat service in a given machine. I need to stop the service, copy a .war file into webapps folder and start the tomcat service. I can see that we have StartService(hostName, serviceName) and StopService(hostName, serviceName) which can be used. But when i try using it in a windows machine, i am getting errors saying unrecognized command. Can someone help in this regard.

Thanks,
Teena.
Feb 10 '09 #1
Share this Question
Share on Google+
9 Replies


Icecrack
Expert 100+
P: 174
if you are getting errors saying unrecognized command that means the command cant be found in windows also for us to understand this more, post your script in code tags

[code] [/CODE ]
Feb 10 '09 #2

P: 15
Expand|Select|Wrap|Line Numbers
  1. sub StartServ {
  2.  
  3.      $computername = '';
  4.      $servicename = 'Apache Tomcat Server';
  5.  
  6.      Win32::Service::GetStatus("\\\\".$computername, $servicename, \%status);
  7.      die "service is arealdy started\n" if ($status{CurrentState} == 4);
  8.  
  9.      Win32::Service::StartService("\\\\".$computername,$servicename) || die "Can't start service\n";
  10.      print "Service started\n";
  11. }
  12.  
  13.  

Here when this sub is called, the error message "Can't start service" is displayed. I read that if we dont specify a machine name , the local machine is taken by default. So i have left that empty. So i guess this sys function does not work in windows.. is there any alternative?
Feb 10 '09 #3

nithinpes
Expert 100+
P: 410
Set:
Expand|Select|Wrap|Line Numbers
  1.    $computername = 'localhost'; 
  2.  
If you leave out the hostname argument for GetStatus method, then local machine will be considered by default. But in your case, you are setting the hostname to null.
Feb 10 '09 #4

Icecrack
Expert 100+
P: 174
Have you even tried using the system commands with backticks

eg.

Expand|Select|Wrap|Line Numbers
  1.  system(`net start Apache Tomcat Server`); 
Feb 10 '09 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
@Icecrack
Isn't that a bit redundant? You need one or the other, but I have never seen anyone try using both at the same time.
Feb 10 '09 #6

Icecrack
Expert 100+
P: 174
the system with backticks waits for the process and when complete returns a value.

don't know if just backticks will do the same.

so blame my teacher for only teaching us one way :)
Feb 11 '09 #7

P: 15
Hi,

I have tried your suggestions. The

Expand|Select|Wrap|Line Numbers
  1.   system(`net start Apache Tomcat Server`);  

does not work either. What intrigues me is that , Win32::Service::StartService is supposed to be used for windows right.. And yes I also tried using localhost as the cumputer name.Thanks for your suggestions though.
Feb 11 '09 #8

Icecrack
Expert 100+
P: 174
@TeenaRoz

Sorry i made an error try

Expand|Select|Wrap|Line Numbers
  1.   system("net start Apache\ Tomcat\ Server");  
Feb 11 '09 #9

P: 15
This seemed to have worked.

Expand|Select|Wrap|Line Numbers
  1.  $servicename = 'net start "Apache Tomcat Server"';
  2. system("$servicename");
Thanks for all your suggestions. Really Appreciate it.
Feb 11 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.