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!

Execute a shell script with output to Tk widget

Status
Not open for further replies.

wlerner

Programmer
Jan 8, 2004
6
US
I have a Tk menu based installer I am working on. When a user selects a widget, I want the widget to execute a bash/csh shell script. I want the output from the shell script to be seen in a new Tk window.

For some reason, the exec command does not want to execute my shell script. It is telling me that there are parentheses in my script that are not necessary. These parentheses are actually used in my shell script when definining functions.

Can anyone help me to re-direct the output of my shell script to a Tk window without Tcl/Tk attempting to interpret my shell script? All I want is stdout from the shell script redirected to a Tk window.

Thank you!
 
Would be best you show us an example of your code to help to help you.
My guess is that there is a simple solution to your problem.

ulis

 
Here is a small example of my code..

function tar () {
tar czvf foo.bar /foobar
}

so on...
 
You showed a piece of shell script.
I can't see where Tcl is used.

I guess you're using a shell script and want to have Tcl called to display the result of the different utilities.

In fact it's more easy to use Tcl to call the utilities and then display the result in a Tk widget.

If you want to keep the shell script, redirect the output of the utility in a file and then call Tcl to display the file:
Code:
  tar czvf foo.bar /foobar >tar.result 2>&1
  wish show.result tar.result &
The Tcl/Tk
Code:
show.result
script could be:
Code:
  pack [text .t] ; # create widget
  set fn [lindex $argv 0] ; # get file name
  set fp [open $fn] ; # open file
  .t insert end [read $fp] ; # insert it in text
  close $fp ; # close file
(not tested)

HTH

ulis
 
First, thank you for the quick responses! I appreciate it!

Sorry about being vauge.. the problem has been solved. I had no problem displaying the BASH shell script in the Tk widdow when I changed the following..

#!/bin/csh

to

#!/bin/sh

It seems that the C-Shell has some different requirements for declaring functions. I was unaware of this at the time, but someone noticed it right away.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top