• Post Reply Bookmark Topic Watch Topic
  • New Topic

can't stop service with java  RSS feed

 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to stop a service with a java program. If i do a net stop from command line I dont have any problem, but with these code I have an error and I cant see nothing in the log. Could you help me please?

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
david luis wrote:... with these code I have an error...

What is the error that you are getting?
 
Carles Gasques
Ranch Hand
Posts: 199
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Luis,

Do you run the cmd shell manually and then type a command and that works?
:-)

Try from your java code


Cheers,
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
it gives me code 1 in the retCode variable
thanks
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
david luis wrote:it gives me code 1 in the retCode variable

Erm...well that might well result from simply stopping the process before its time.

I hate to say, but this strikes me as sysadmin stuff - not really what Java was designed to do.

You can probably do it, but I suspect you'd be far better off placing the entire lifecycle of the process in a Java scheduler (of which there are several). Simply trying to come up with a way to "kill" any old process on your system with Java is likely to be fraught with difficulties.

Winston
 
Carles Gasques
Ranch Hand
Posts: 199
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Upps,
I have made the wrong assumption that you run in a windows environment.
My fault!

Do you can run from unix console the same command, with the same user that runs the java app and from the same directory where the java app runs?

Cheers
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carles Gasques wrote:Hi Luis,

Do you run the cmd shell manually and then type a command and that works?
:-)

Try from your java code


Cheers,


Is windows. Until tomorrow I cant try it?
When I try it I post the result.
Thanks
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try with cmd /c

In my PC I dont have any problem but when I exexute the program in the server it says me that is stopped but the program doesn't do nothing. I see that because the program dont take long.

 
Carles Gasques
Ranch Hand
Posts: 199
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confused,

you run your java code, that executes the command "cmd /c net stop <your service>" in a windows server and the result is a return code 0 (OK)
and a message saying "<your service> is stopped", but the service <your service> is still running in the windows server?
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carles Gasques wrote:I'm a bit confused,

you run your java code, that executes the command "cmd /c net stop <your service>" in a windows server and the result is a return code 0 (OK)
and a message saying "<your service> is stopped", but the service <your service> is still running in the windows server?


No sorry for the confusion,
I execute with a service and it works. But when I'm trying to execute with other service if fails.



 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because "MicroStrategy Intelligence Server" is not a service name. It's the display name for the service, but not the service name itself. You can find the latter by double clicking on the service from the Services screen; it's the top value.
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:That's because "MicroStrategy Intelligence Server" is not a service name. It's the display name for the service, but not the service name itself. You can find the latter by double clicking on the service from the Services screen; it's the top value.


Is the same name:


 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Odd. That's the first service name I remember seeing that contains spaces.

Anyway, those spaces are still the problem. Right now your command will see multiple arguments. Enclose the service name in quotes:
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
david luis wrote:I execute with a service and it works. But when I'm trying to execute with other service if fails.

David,

Did you actually read my post? It may not be what you want to hear, but I'll say it again: This is not what Java was designed for.

Starting and stopping services is an admin function; and I'm quite sure that Windows provides plenty of ways to do it yourself. If you want it automated, then I suggest you look at a scheduler.

If you can't do that, and you absolutely, positively, MUST have everything controlled by Java; then Java should control the entire process lifecycle. Otherwise, you're in the realms of a kludge, and I suspect you're in for a world of hurt.

Winston
 
david luis
Ranch Hand
Posts: 53
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Odd. That's the first service name I remember seeing that contains spaces.

Anyway, those spaces are still the problem. Right now your command will see multiple arguments. Enclose the service name in quotes:


Many thanks.
It workksssssss!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!