• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue in executing System Command through Java  RSS feed

 
ashwin bala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to execute a system command through java.I am trying to check whether a particular service is running in a
remote PC.When i execute a same command in local PC i.e. without IP Address, then i am getting proper output response.But
when i use remote IP Address and BufferedReader to get the response ,the application is getting hang after
BufferedReader.readLine() method call.. I have attached the code which i have written.



The execution stops after line 17: bufferedReader.readLine(); with out any error.Waiting for the reply. Thanks in advance..
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ashwin,
This question has nothing to do with EJB. Please CarefullyChooseOneForum before posting. I will be moving this thread to an appropriate forum.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This probably means the command threw an error. And you are reading only the input stream and not the error stream.

As you are dealing with Runtime, I will point you out to one of the most important articles regarding this: When Runtime.exec() won't
 
ashwin bala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ranganathan,
I went through the article.They have mentioned about my problem in page 2.But When i tried the solution and guidelines
still i am facing the same problem.And all the right example which they have mentioned were not working when i used my command(sc <ipaddress> query <servicename>) instead "JAVAC"
which is mentioned there.

Thanks & Regards,
Ashwin kumar
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you then change your code as provided in page 4 (GoodWindowsExec)? If so and if you still face the problem, did you try and run the command from command line first? how do you run it and what happens when you do that?
 
ashwin bala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes . I tried it.Every time ,things are getting blocked after the readLine statement.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I mean, what happens when you execute the command directly - outside the program?
 
ashwin bala
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to get the status(running/stopped) of the service and other details without any problem.
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that "sc" command one of those annoying commands which pop up a dialog box to tell you something, and wait for you to click OK? If so, look for a command option which tells the command not to do that.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!