471,873 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

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.

Feb 10 '09 #1
9 5491
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 {
  3.      $computername = '';
  4.      $servicename = 'Apache Tomcat Server';
  6.      Win32::Service::GetStatus("\\\\".$computername, $servicename, \%status);
  7.      die "service is arealdy started\n" if ($status{CurrentState} == 4);
  9.      Win32::Service::StartService("\\\\".$computername,$servicename) || die "Can't start service\n";
  10.      print "Service started\n";
  11. }

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
410 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1.    $computername = 'localhost'; 
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
174 Expert 100+
Have you even tried using the system commands with backticks


Expand|Select|Wrap|Line Numbers
  1.  system(`net start Apache Tomcat Server`); 
Feb 10 '09 #5
3,503 Expert Mod 2GB
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
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

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
174 Expert 100+

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 YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.