469,327 Members | 1,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Starting and stopping service

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
9 5387
Icecrack
174 Expert 100+
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
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
410 Expert 256MB
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
174 Expert 100+
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
3,503 Expert Mod 2GB
@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
174 Expert 100+
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
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
174 Expert 100+
@TeenaRoz

Sorry i made an error try

Expand|Select|Wrap|Line Numbers
  1.   system("net start Apache\ Tomcat\ Server");  
Feb 11 '09 #9
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.

Similar topics

2 posts views Thread by Rajesh Abraham | last post: by
2 posts views Thread by Soren S. Jorgensen | last post: by
reply views Thread by s.kapitza | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.