Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Calling a telnet application at the button click

Posted by skumar003 (skumar003), 28 January 2003
I have an application that connects to a host. That needs to be executed at the command line.

execute port@host this.package.

How do I call this in a GUI button so that I click the button I get that executed.

Cheers,


Posted by admin (Graham Ellis), 28 January 2003
Then you'll be wanting the Tk extension and the expect extension - you'll find them together in "expectk".

Wrap the spawn send and expect sequence (and everything
else you want to do to run the the remote command) into a
proc, and create a widget (probably a button) that calls it up with its -command option.

Use a pack geometry manager to display the button, and when your code reaches the end it will wait for button hits.   You'll probably also want to create and pack a label onto which to display your results, and you might want to have a look at updateidlestasks if your remote application can take a while to run - otherwise your user may be left thinking that the application has hung.

It's fabulous fun writing this sort of thing, code typically turns out quite short, but you really need a good head on your shoulders and to understand things like deferred blocks ....

Posted by skumar003 (skumar003), 28 January 2003
Have U seen a free source example of this kind anywhere on the net?

Posted by admin (Graham Ellis), 28 January 2003
Well - it's really just a question of combining Tk techniques and Expect techniques ... can't say that I've seen an example posted for free on the net that fulfills the criteria;  the nearest I can offer is an application that spawns a ping and reports back - on our web site at
http://www.wellho.net/resources/tcl.html
and (you're in luck!) it's the course example "tkpingle" that's mentioned on the "view sample program" box.

Posted by skumar003 (skumar003), 28 January 2003
Can I   invoke a  batch file by the click of a button?

-----Example-of-what-it-is-----------
#!/usr/local/bash
connect port@host scriptfile
--------------------------------

---What I want to achieve--------------

button .redo -text "Connect to NE" -command {
   #!/usr/local/bash
connect port@host scriptfile

}
--------------------------------

Posted by admin (Graham Ellis), 29 January 2003
If the batch (script) file is located (and to run) on the computer that's running the Tcl/Tk script then, yes ... have a look at the exec command, and also the catch command so that any errors it generates won't cause the whole Tcl program to fail.

If the batch command script requires interaction, or to be run on a remote machine (as your initial question kinda implies) then expectk is the thing to use.  There's thorough coverage in Don
Libe's book "Exploring Expect" - full book details at
http://www.wellho.net/book/1-56592-090-2.html




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho