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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get input into console application

Status
Not open for further replies.

piedycat

Technical User
May 31, 2002
7
GB
OS win98

Hi, i've got an console application launcher (below) which redirects the dos box output into a text window, this is fine if no input is required from the user but how do I get keyboard input into the application if it requires it?
TIA
Mark

TCL code follows:

# console show

button .app -text "select exe file" -command getappfile
pack .app -pady 5

# Create a text widget to log the output

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

set but [button .run -text "run exe file" -command Run]
pack .run -pady 2
button .quit -text "exit" -command exit
pack .quit -pady 2



proc getappfile {} {
global command but
set types {
{".exe files" {.exe}}
}
set command [tk_getOpenFile -filetypes $types]
}


proc Run {} {
global command input log but
if [catch {open "|$command"} input] {
$log insert end $input\n
} else {
fileevent $input readable Log
$log insert end $command\n
$but config -text Stop -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
}
}

proc Stop {} {
global input log but
set line "done...."
$log insert end $line\n
$log see end
catch {close $input}
$but config -text "Run exe file" -command Run
}

 
Mark,
I used a DOS program that just dumps some text to the console then waits for a "q" from the user, then exits.

Then I add/change few things in your code...

proc Run {} {
global command input log but
if [catch {open "|$command &" r+} input] {
$log insert end $input\n
} else {
fconfigure $input -blocking 0 -buffering none -translation auto
fileevent $input readable Log
$but config -text Stop -command Stop
}
}

# Read and log output from the program

proc Log {} {
global input log
if [eof $input] {
Stop
} else {
gets $input line
set chr_qty [string length $line]
$log insert end $line\n
if {$line == "Press q to quit"} {puts $input q}
$log see end
}
}

here, sending the expected "q" from Tcl to the DOS
program when message "Press q to quit" arrives at the
stdout.

jorge
 
Jicote,
Thanks for your suggestion but I cannot get it to work for me. I have a test console application which prints something, waitts for a carrage return then prints something else. Sure it waits for the input but nothing happens when I input anything in the text widget, or am I missing something.
Regards
Mark.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top