URGENT : running commands from a tcl/tk program
From: Amith (amith_kumar.vallabhaneni_at_alcatel.be)
Date: 10/31/03
- Next message: Donald Arseneau: "Re: entry widgets and tabbing"
- Previous message: Adrian Davis: "Problem drawing line on canvas"
- Next in thread: Cameron Laird: "Re: URGENT : running commands from a tcl/tk program"
- Reply: Cameron Laird: "Re: URGENT : running commands from a tcl/tk program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 Oct 2003 03:07:46 -0800
I am trying to write a program which executes user commands, like
ping,etc.
My program runs as long as I pass a single parameter, like, "notepad",
"mspaint".
When I want to execute, "ping 127.0.0.1", I get the error message -
"coundn't execute "ping 127.0.0.1", no such file or directory".
But if I run a single command "ping" and leave the arguments field
empty in the Tk widget, the output is correct and as expected.
Here is my code:
###########################################################################
#This program Runs certain commands line "notepad","mspaint",etc, but
doesn't run "ping","cmd", etc
#_______________________________________________________________________________________________________
# Title of the Widget
wm title . CommandRun
#This frame is for command label and entry field
frame .level1 -borderwidth 10
pack .level1 -side top -fill x
#This frame is for argument label and entry field
frame .level2 -borderwidth 10
pack .level2 -side top -fill x
#Button to quit the program
button .level1.quit -text Quit -command exit
#Button to run the program
set but [button .level1.run -text "Run" -command Run]
pack .level1.quit .level1.run -side right
#A label and an entry field for command input
label .level1.l -text Command: -padx 7
entry .level1.cmd -width 20 -relief sunken \
-textvariable command
#A label and entry field for argument(s) input
label .level2.l -text Argument(s): -padx 3
entry .level2.arg -width 20 -relief sunken \
-textvariable argument
#Packing the command label and entry field
pack .level1.l -side left
pack .level1.cmd -side left
#Packing the argument label and entry field
pack .level2.l -side left
pack .level2.arg -side left
#Binding the buttons used to run and stop the program
bind .level1.cmd <Return> Run
bind .level1.cmd <Control-c> Stop
#To get the focus to the command entry field
focus .level1.cmd
#This frame sets and binds the log window and scroll bar
frame .t
set log [text .t.log -width 80 -height 10 \
-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
#Procedure to run the command with the given arguments
proc Run {} {
global command log but
global argument
#set cwa [concat $command $argument]
set argument [.level2.arg get]
if [catch {exec [concat $command $argument]} result] {
$log insert end $command\n
$log insert end $argument\n
$log insert end $result\n
$log insert end \n
}
$but config -text Stop -command Stop
}
#Procedure to log the output of the run procedure
proc Log {} {
global log
if [eof $result] {
Stop
} else {
gets $result line
$log insert end $line\n
$log see end
}
}
#Procedure to stop the Run procedure
proc Stop {} {
global but
catch {close $result}
#This statement changes the label of the button from "Run" to "Stop"
and back
$but config -text "Run" -command Run
}
##########################################################################
Please help me at the earliest. Please let me know where I went wrong
in the code and what I should do. I am a beginner.
- Next message: Donald Arseneau: "Re: entry widgets and tabbing"
- Previous message: Adrian Davis: "Problem drawing line on canvas"
- Next in thread: Cameron Laird: "Re: URGENT : running commands from a tcl/tk program"
- Reply: Cameron Laird: "Re: URGENT : running commands from a tcl/tk program"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]