Unable to start telnet session from java - java

I am currently working on a Java Applet which is supposed to start a telnet session via command line. My current approach is to run:
String connectionString = "cmd /c start cmd.exe /k \"telnet\"";
Runtime.getRuntime().exec(connectionString);
When I execute this, cmd.exe opens but displays "telnet is not recognized as an internal or external command, operable program or batch file".
I do have telnet set up, there is no problem opening a cmd window and executing telnet there. I also tried to run the above snippet with other programs (rasdial, jarsigner) and it perfectly works.
Why would the cmd.exe not recognize telnet when started from java? Any help highly appreciated!

If the JVM is 32-bit on a Windows 7 system, then according to this post
...on a 64-bit Windows 7 system, telnet only works when launched from a 64-bit application....
You can try Apache Commons Net API which support telnet protocol. You can refer this sample example. You can also refer this reference guide.

Related

Windows OS commands are not executing in Spring Shell

I am using spring shell to develop command line interface application, I am facing one issue in windows machine, On Linux machine i am able to execute OS commands by using !<OS Command>,
but this is not working in windows machine. Spring shell says
Unable to execute command, The system can not find the specified command.
Please let me know how can i execute windows command in Spring shell running in windows platform( commands like date, time,path etc)
Thanks in advance.
date, time, path, etc. are built-in commands of the windows command shell. It seems that these built-in commands are not available within spring-shell and spring-shell looks after commands which exist real as file in the windows path.
Windows-Commands like calc (! calc) which are not built-in are available.

running application from cmd as administrator through java code

I executed the netsh command from the CMD that was manually opened by me by right clicking the CMD icon from the start and then selecting run as administrator from the options.It worked fine.Now I tried to run the netsh command through my java code,then it is not working.Nothing is happening when i run that code.I want to ask that I can run applications like notepad.exe from the cmd by calling appropriate methods of the runtime class from my java code,But how can I open the same application with the administrator priviliges from my java code.r.exec("notepad"); where r is an object reference to the runtime class will run the application,but the notepad so opened will not be in administrator mode.Actually I guess that learning to run the application in administrator mode from CMD will be enough to do the work done as The corresponding CMD command will be passed as the argument to the exec() method of the Runtime class.So my questions are:
How to run any application from CMD in windows 8 with administrator privilliges?
The way i want to implement the use of netsh is a good thing to practise or there is some other way out i must use these commands from my java code.
I have seen some commands while googling but they where not working out for me,like runas /user:administrator "notepad.exe" etc.
Thanks
You cannot use the runas /user:administrator approach, as that requires a password input which you cannot provide from an external source (such as a Java application) for security reasons.
I had a similar issue to you in the past, and I solved it using PsExec, running the process on localhost with an administrator username and password allowed me to execute external applications as an administrator.
Using your example you could run:
PsExec.exe \\\\127.0.0.1 /accepteula -u USER -p PASSWORD notepad.exe
The "/accepteula" flag prevents the requirement to accept the EULA interactively when run on a machine for the first time.
This approach may require a bit of tweaking to get working with your setup, but hope it gives you a starting point.

Unable to keep Selenium Server Running after Putty Close

First, install the Selenium Server:
Download a distribution archive of Selenium Server.
Unzip the distribution archive and copy selenium-server-standalone-2.9.0.jar (check the version suffix) to /usr/local/bin, for instance.
Start the Selenium Server server by running java -jar /usr/local/bin/selenium-server-standalone-2.9.0.jar.
I can let it run but when i close my putty, the server shuts down. Is it suppose to be that way? As in, does the code initialize the server when they need? or how do I find a way to keep it running?.
This is normal, when you close putty all your commands will be killed.
To keep your commands running, you need either to :
Create a script that will launch this command
run your command using : nohup java -jar /usr/local/bin/selenium-server-standalone-2.9.0.jar &

Java Runtime.exec running java problem

I have a simple server application, which I would like to run in the background. The following line works for me:
Runtime.getRuntime().exec("cmd /c start java -jar ..\\server\\server.jar -Dlog4j.configuration=file:src\\test\\resources\\log4j.properties -filename src\\test\\resources\\server.properties");
But it displays the cmd window and I am unable to destroy it. So I would like to use
Runtime.getRuntime().exec("java -jar ..\\server\\server.jar -Dlog4j.configuration=file:src\\test\\resources\\log4j.properties -filename src\\test\\resources\\scIntegration.properties");
But it simply doesn't connect to the server. So why is that?
A related question. How do I end the process? It is a server that "doesn't end". So I have to kill it and I would assume, that running the java only command would be capable to be destroyed, but with the cmd I have no luck there.
You should split your command into an array in which first argument is the actual command to run and all the rest are command like arguments:
Runtime.getRuntime().exec(new String[] {"/usr/bin/java", "-jar", "..\\server\\server.jar" ...});
Try using an absolute path to the java programm.
For destroying: exec() returns a java.lang.Process, which you should be able to destroy. If not, you have to implement some type of callback to shut your server down, e.g. listening on a specific prot for a shutdown command.
The server is outputing something to stdout and in the shortened command version it didn't have a place to output, so it got stuck while trying to output some data. The solution is to pipe the stdout to eg some file.

How do you run jvisualvm.exe under the local system account under Windows Server 2003?

I am running GlassFish 3.0.1 as a windows service under Windows Server 2003 with Java 1.6 u 20, and am generally happy.
I would like to be able to use VisualVM on this JVM and used Unable to use JConsole with Tomcat running as windows service as a starting point, but starting with
PsTools\PsExec.exe -i -s "C:\Program Files\Java\jdk1.6.0_20\bin\jvisualvm.exe"
results in a jvisualvm.exe and a nbexec.exe process showing up in Task Manager with SYSTEM as the user but I do not see any GUI from the program as I do when I run it manually as myself. I am logged in with Remote Desktop from Windows 7 in case that makes any difference.
Other interesting points:
at 10:55 /interactive cmd.exe
reports a new job has been added, but does not open a CMD window at 10.55.
The description of how to register VisualVM as a service reports the service to start but no GUI shows up. http://blogs.oracle.com/nbprofiler/entry/monitoring_java_processes_running_as
Have anybody gotten this to run under Windows Server 2003?
The way I'm able to get this to work is to make sure that you remote desktop to the server's "console" session.
Simply put, when you open mstsc.exe append the text " /admin" to the computer name you are trying to connect to. For instance, if you were trying to connect to a server called "FOO", then in the Computer name text box in mstsc.exe, you would enter "FOO /admin".
After connecting and logging in to the server, you can execute your PsExec command. You should then see Visual VM with the GlassFish process you are trying to connect to.
For more info about connecting to the console session with remote desktop in Windows, have a look at the "How to Connect to the Console" section http://support.microsoft.com/kb/278845.
Also, for those looking for PsExec.exe, you can get it from the PsTools package from Microsoft at technet.microsoft.com/en-us/sysinternals/bb897553.aspx.

Categories