473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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.

Thanks,
Teena.
Feb 10 '09 #1
9 5713
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,509 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

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

Similar topics

2
by: Rajesh Abraham | last post by:
I have a Windows Service and in the OnStart, I am initializing the BusinessLayer Object and calling a method of the object, which normally takes about 10 mts to finish execution. Now when I...
1
by: Stu | last post by:
Hi, I have been asked to write a little app the restarts a windows service under certain conditions. It is not a service written in .Net? thanks in advance, Stu
2
by: SQLScott | last post by:
In the OnStart sub of my service (as the service is starting up) I check for certain things. If one of a few things don't jive, I want to "cancel" the starting of the service. How do I...
2
by: Soren S. Jorgensen | last post by:
Hi, How do I see, from within my main method, in what context my assembly, containing my service program, is executed ?? I want to be able to detect if the assembly is executed by the service...
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
3
by: Cenarius | last post by:
Hi, I need some help, i don't know much about programming other than executing them get getting them from scripting sites. My program is it won't start a service if the startup type is Disabled. it...
0
by: s.kapitza | last post by:
Hi, try M$S servicebug 3 regards s.kapitza alghaden@alumni.fdu.edu (Ahmad) wrote in message news:<4a75f4b7.0308080649.49105373@posting.google.com>...
4
by: rottmanj | last post by:
I have written an application that installs a service and then is supposed to start the service. Everything works great except for the service starting(either with AfterIntall or starting it from the...
5
by: mwizniki | last post by:
I'm trying to start the MSFTPSVC, and I need to add a user/password. This has to be Windows 7 friendly. Starting the service is the easy part, but I'm having difficulty locating in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.