473,585 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Starting and stopping service

15 New Member
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(ho stName, serviceName) and StopService(hos tName, 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 5744
Icecrack
174 Recognized Expert New Member
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
TeenaRoz
15 New Member
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 Recognized Expert Contributor
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 Recognized Expert New Member
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 Recognized Expert Moderator Specialist
@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 Recognized Expert New Member
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
TeenaRoz
15 New Member
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 Recognized Expert New Member
@TeenaRoz

Sorry i made an error try

Expand|Select|Wrap|Line Numbers
  1.   system("net start Apache\ Tomcat\ Server");  
Feb 11 '09 #9
TeenaRoz
15 New Member
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
3354
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 start the Service from Administrative Tools services, it shows starting and after sometime throw error that the service does not respond in time and...
1
1014
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
1445
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 accomplish this? Currently I am using the Stop method of the ServiceController but that does not seem to be working. Is it possible to "stop the start"...
2
1646
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 system (say started from the Services applet) or if it was executed from a command line (in which case the service won't start). The reason for...
5
4468
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 the Main() function: // if this is not the first instance of this application, exit // immediately. Allow only one instance in the system if...
3
4121
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 will try and stop a service that is disabled and will display msg "Error stopping service." if i run script on a service that is already running, it...
0
1466
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
3365
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 window service manager). The error I get is System.InvalidOperationException: Cannot start service qbLinxService on computer ',', ------>...
5
1333
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 ServiceController.Execute custom command method how I can add/delete a username and password.
0
7835
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7947
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5707
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5386
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3831
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3856
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2340
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.