Hi All - I have an issue when using a new thread to run an external .exe file (Putty in this case)

When I don't use a new thread Putty will start and stay open and let me do what I need to as normal, however it then hangs the rest of the application so you can't use it until you are finished with Putty - So I thought I would put it in a new thread. I use this method quite a bit in my application and don't have any issues so i'm wondering what I have done wrong here, I call other external .exe files and also start some external Java processes using a new thread and they work OK (using the same method)

It seems to me that the putty process doesn't seem to give any output and so the thread assumes it has closed and shuts down, or I need to inform the thread to wait and send it a message to clean up when I am finished. If I connect to a host and need to add the RSA key to the cache then Putty will stay open in the new thread until I click OK to save the key, then as soon as I have done that it closes

Can anyone point me in the right direction?

Below is some code for working and not working scenarios, the code below has been altered to run from a button click as in my app it's done from a popup menu and I don't think the issue is with the calling function (but I could be wrong)......

Hi Kayaman - I have read the article previously and I have implemented both the runtime.exec and processbuilder methods to test, both the runtime.exec and also processbuilder ways of running putty work when not in a new thread

I think (hope..) my issue is with threading and not the way I call the process to run. After doing some testing I have found that when I specify my arguments within the class I created (called MyPutty) for IP Address, user and pwd the session stays open until I am done with it - however when I pass the IP, user and pwd from another class the session closes straight away so it looks like my problem is something to do with starting the new thread in my main class and then passing it correctly to the MyPutty class, I think I need to somehow monitor the thread and inform it when it needs to close but I don't really know how to do this

I eventually worked out that the IP I was passing was in fact incorrect, the address didn't support SSH and so the session closed immediately. Now I pass the correct address all is working and sessions stay open (in a new thread)

facepalm

BTW - can Putty only have maximum 1 session open? It only seems to work with 1 instance open which is a bit of a problem; as I usually can have up to 4/5 SSH sessions open at the same time (in different windows) the issue I have is that each session needs to be in a interactive window, and not just a plain SSH session where I can send commands to.......I have messed with Jsch and Ganymed for opening and using SSH sessions and they work but there is no interactive window shells available with those implementations, and unfortunately I require a window based interactive session......does anyone know of a good terminal emulator for Java in Swing??

I used the WRQ Reflections control for .NET and it does everything I need and more but theres nothing available for Java so have been trying Putty......if anyone has a good Swing based control I would like to have a look. The Reflections control is ActiveX based so is there a way to use the DLLs in Java?

Hi Gimbal2 - google is my friend (other search engines are available.....) and I have looked at loads of results but none of them gets close to what i'm looking for, nearly all the telnet/ssh libraries don't do interactive window stuff (although I admit I do want the moon on a stick....)

The best I looked at so far is Gritty (seems to be base on JSch terminal) but it just can't handle telnet or ANSI formatting and doesn't do VT100 emulation, although the plain SSH terminal is OK and usable

The rest are SSH/Telnet libraries and I will need to write a terminal emulator and some other stuff to make them do what I need....TBH i'm not good enough a programmer to do that. I just make small apps that make my life at work easier (and also my work mates) i'm not a professional programmer and nothing is for commercial reasons

I use the Reflections .NET control in my old .NET app and it has absolutely everything built in, all functions of Reflections are callable via native code so it makes life so easy - I was hoping for that kind of solution in Java, because basically i'm lazy!! The reason is that the equipment I connect to uses Telnet and SSH but they aren't 'normal' servers as such, I work in 'comms and each vendor has their own language that you need to use over the Telnet/SSH session so I need a plain terminal emulator that handles XTERM/VT100/VT102, ANSI etc. Reflections did this for me and had a great way to send commands in just about any format and then store results etc

Anyway - apologies if i've been spamming the forum with stupid questions, I do try to work through google answers before posting here....

BTW, I tried the google search with SSH terminal and got way more/better results than searching for "Java Telnet" or "Java Terminal Emulator" so am going to have a look at some of those as well, thanks for your help!

There are several. I've been using a combination of JTA and Ganymed for a couple of years with success. You just have to write a very simple JTA plugin that calls Ganymede to do the SSH-2 part. (JTA only supports SSH-1).

OK - after some searching and investigating and quite a few trials I found this:

http://tech.cryptzone.com/mindterm/

It's a great library with just about everything I was looking for! There are good examples for SSH and Telnet clients and they are fairly easy to use (even for me!) and the sessions/terminals are easily customisable, all the common terminals are emulated in a very good way

I tried some of the other suggestions for JTa and JTerm and also commons.net but they didn't tick too many boxes as stand-alone solutions, this one has great emulation and also the terminal properties are easily set from either a properties file or via code (which was a big plus for my requirements) and there are good options available to set just about anything you would want to

I have incorporated this into my app and it is really useful - just though I would pass on my findings as this is a great set of tools and certainly the best and easiest of the libraries I have tried.....In my humble opinion......