Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I open an editor (vi,emacs) within a Tcl shell?

Status
Not open for further replies.

bbanner

Programmer
Aug 3, 2001
5
US
I'm writing a command-line Tcl script, and I would like to open up a text editor (vi, emacs, etc.) to allow the user to enter formatted input.

My initial attempt at this failed. Here's what I did:
1. created a unique temporary file name
2. used the "exec" command to open the unique file with the editor
3. open the file using the "open" command
4. read the contents of the file using the "read" command

This approach almost works. The only problem is that the editor is not brought to the foreground, so you can't actually see the text you are entering. I can blindly type some text, save the file and exit the editor at which point the Tcl script continues executing at step 3 and 4 and I actually read the text I just blindly entered.

Is there a way to get the editor to come into the foreground (STDOUT) so that I can see the text I'm entering?
 
Have you looked at expect for this if you are in a *nix environment?
Something as simple as this snippet does what you want.

#!/usr/bin/tclsh
package require Expect

spawn -noecho /usr/bin/vi [lindex $argv 0]
interact
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top