Contained in the following is my code. For whatever reason the replys with usage commands if the user types in any unix command word, such as mkdir, rm, ls, ect.
We want a normal text entry box, so that we can have the user type in any word, regardless if it is a unix command word or not, and generate the same response.
***********************************************************
#Edmund Wong EECS 281
#!./splaywish -f
# This makes a web interface for our program
# title
wm title . "DragonSteel"
# create a window frame
frame .top -borderwidth 20
pack .top -side top -fill x -padx 100 -pady 50
# create the search button and quit button
button .top.quit -text "Quit" -command exit
set but [button .top.run -text "Search" -command Run]
pack .top.quit .top.run -side right -padx 2
# create a labeled entry for the command for searching
label .top.l -text Search: -padx 0
entry .top.cmd -width 30 -relief sunken -textvariable command
pack .top.l -side left
pack .top.cmd -padx 5 -side right -fill x -expand true
# set up key binding to the buttons
# so user can type using keyboard
bind .top.cmd <Return> Run
focus .top.cmd
#create a text widget to log the output
frame .t
set log [text .t.log -width 80 -height 30 -borderwidth 2 -relief raised -setgrid true -yscrollcommand {.t.scroll set}]
scrollbar .t.scroll -command {.t.log yview}
pack .t.scroll -side right -fill y
pack .t.log -side left -fill both -expand true
pack .t -side top -fill both -expand true
# run the program an ararnge to read its input
proc Run {} {
global command input log but
if [catch {open "|$command |& cat"} input] {
$log insert end $input\n
} else {
fileevent $input readable Log
$log insert end $command\n
$but config -text Search -command Stop
}
}
# read and log output from the program
proc Log {} {
global input log
if [eof $input] {
Stop
} else {
gets $input line
$log insert end $line\n
$log see end
}
}
# stop the program and fix up the button
proc Stop {} {
global input but
catch {close $input}
$but config -text "Search" -command Run
}
We want a normal text entry box, so that we can have the user type in any word, regardless if it is a unix command word or not, and generate the same response.
***********************************************************
#Edmund Wong EECS 281
#!./splaywish -f
# This makes a web interface for our program
# title
wm title . "DragonSteel"
# create a window frame
frame .top -borderwidth 20
pack .top -side top -fill x -padx 100 -pady 50
# create the search button and quit button
button .top.quit -text "Quit" -command exit
set but [button .top.run -text "Search" -command Run]
pack .top.quit .top.run -side right -padx 2
# create a labeled entry for the command for searching
label .top.l -text Search: -padx 0
entry .top.cmd -width 30 -relief sunken -textvariable command
pack .top.l -side left
pack .top.cmd -padx 5 -side right -fill x -expand true
# set up key binding to the buttons
# so user can type using keyboard
bind .top.cmd <Return> Run
focus .top.cmd
#create a text widget to log the output
frame .t
set log [text .t.log -width 80 -height 30 -borderwidth 2 -relief raised -setgrid true -yscrollcommand {.t.scroll set}]
scrollbar .t.scroll -command {.t.log yview}
pack .t.scroll -side right -fill y
pack .t.log -side left -fill both -expand true
pack .t -side top -fill both -expand true
# run the program an ararnge to read its input
proc Run {} {
global command input log but
if [catch {open "|$command |& cat"} input] {
$log insert end $input\n
} else {
fileevent $input readable Log
$log insert end $command\n
$but config -text Search -command Stop
}
}
# read and log output from the program
proc Log {} {
global input log
if [eof $input] {
Stop
} else {
gets $input line
$log insert end $line\n
$log see end
}
}
# stop the program and fix up the button
proc Stop {} {
global input but
catch {close $input}
$but config -text "Search" -command Run
}