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

captue win32 console application output

Status
Not open for further replies.

piedycat

Technical User
May 31, 2002
7
0
0
GB
OS win98
I want to capture the output to a DOS box as it happens.
I launch the app using exec and can redirect the output to a file ( exec app.exe > out.txt & ) once this file is written & closed I can open it and display the contents, but how can I just capture a line at a time from the DOS box window so I can see events in real time ?
TIA
Regards
Mark
 
Will
set ofd [open "|dosexecutable" r]
fconfigure $ofd -buffering line

while {![eof $ofd]} {
if {[gets $ofd line]} {
puts $line
}
}
as a general idea work for you?
 
Thanks for the suggestion but until the dosexecutable finishes it hangs then spits all the output in 1 go, what i want is it to spit each line that the dosexecutable writes out as it happens.
It does have the advantage of not having to write an intermediate file though.
Any further suggestions most welcome
Regards
Mark
 

Here is an example of polling i/o on a socket like you seem to want for your application, same idea for your program.

fconfigure $sock -buffering line -translation auto
fileevent $sock readable [read_line $sock 1200]

proc read_line {sock {mytime "1200"} {i "0"}} {
while {![eof $sock]} {
#puts "Inside while loop."
after $mytime;
if {[gets $sock line] > 0} {
puts "$line."
} else {
incr i
puts "Recalling after $time.,$i line read called"
after $mytime [list catch {read_line $sock $mytime $i}]
}
}
}

This kind of thing is just a matter of tuning some parameters to fconfigure and getting your polling
right in my experience.

 
It sounds as though you're running into problems with your DOS executable buffering its output. This is typical behavior of most applications that use the standard I/O libraries on virtually all platforms. See my response to thread287-213612, "Sporadically arriving data from a stream," for more information on the problem and possible solutions to it. - Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Ken
Thanks very much, yes it was output buffering which was causing the problems. Adding fflush(stdout) after each printf in the original C source sorted it out.
The original was not a true dos executable but a win32 console application.Is there anyway of turning stdout buffering off ? for those occasions when I don't have access to the source code?
Mark
 
If you can't modify the C code, install the "Expect" extension In this extension there is the command unbuffer which disables the output buffering that occurs when program output is redirected!

=:) Anto.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top