Artifact
7671b30ba682ad08fa7967130d4842c08a999ec4:
Attachment "t.tcl" to
ticket [439114ffff]
added by
chris_nelson
2001-07-06 23:52:52.
0000: 70 72 6f 63 20 50 74 69 45 78 65 63 52 65 61 64 proc PtiExecRead
0010: 52 65 73 75 6c 74 73 20 7b 20 66 69 64 20 6f 75 Results { fid ou
0020: 74 43 6d 64 20 7d 20 7b 0a 20 20 20 20 67 6c 6f tCmd } {. glo
0030: 62 61 6c 20 50 74 69 45 78 65 63 0a 0a 20 20 20 bal PtiExec..
0040: 20 23 20 47 72 61 62 20 74 68 65 20 6e 65 78 74 # Grab the next
0050: 20 6c 69 6e 65 20 6f 66 20 6f 75 74 70 75 74 20 line of output
0060: 66 72 6f 6d 20 74 68 65 20 6f 70 65 6e 20 70 69 from the open pi
0070: 70 65 2e 0a 20 20 20 20 73 65 74 20 6c 69 6e 65 pe.. set line
0080: 20 5b 72 65 61 64 20 24 66 69 64 5d 0a 0a 20 20 [read $fid]..
0090: 20 20 23 20 53 74 6f 72 65 20 74 68 65 20 6f 75 # Store the ou
00a0: 74 70 75 74 20 66 6f 72 20 5b 70 74 69 45 78 65 tput for [ptiExe
00b0: 63 5d 2e 0a 20 20 20 20 61 70 70 65 6e 64 20 50 c].. append P
00c0: 74 69 45 78 65 63 28 46 69 6f 4f 75 74 29 20 24 tiExec(FioOut) $
00d0: 6c 69 6e 65 0a 0a 20 20 20 20 23 20 57 72 69 74 line.. # Writ
00e0: 65 20 74 68 65 20 72 65 73 75 6c 74 73 20 28 74 e the results (t
00f0: 6f 20 73 74 64 6f 75 74 2c 20 73 74 64 65 72 72 o stdout, stderr
0100: 2c 20 6f 72 20 6e 6f 6f 70 29 0a 20 20 20 20 24 , or noop). $
0110: 6f 75 74 43 6d 64 20 24 6c 69 6e 65 0a 0a 20 20 outCmd $line..
0120: 20 20 23 20 43 68 65 63 6b 20 66 6f 72 20 45 4f # Check for EO
0130: 46 2e 0a 20 20 20 20 69 66 20 7b 20 5b 65 6f 66 F.. if { [eof
0140: 20 24 66 69 64 5d 20 7d 20 7b 0a 20 20 20 20 20 $fid] } {.
0150: 20 20 20 70 75 74 73 20 73 74 64 65 72 72 20 22 puts stderr "
0160: 47 6f 74 20 45 4f 46 20 6f 6e 20 24 66 69 64 22 Got EOF on $fid"
0170: 0a 20 20 20 20 20 20 20 20 73 65 74 20 50 74 69 . set Pti
0180: 45 78 65 63 28 46 69 6f 53 74 61 74 75 73 29 20 Exec(FioStatus)
0190: 5b 63 61 74 63 68 20 7b 20 63 6c 6f 73 65 20 24 [catch { close $
01a0: 66 69 64 20 7d 20 73 74 61 74 75 73 5d 0a 20 20 fid } status].
01b0: 20 20 20 20 20 20 70 75 74 73 20 73 74 64 65 72 puts stder
01c0: 72 20 22 5c 74 53 65 74 20 46 69 6f 53 74 61 74 r "\tSet FioStat
01d0: 75 73 20 74 6f 20 24 50 74 69 45 78 65 63 28 46 us to $PtiExec(F
01e0: 69 6f 53 74 61 74 75 73 29 5c 0a 20 20 20 20 20 ioStatus)\.
01f0: 20 20 20 20 20 20 20 20 20 20 20 66 72 6f 6d 20 from
0200: 63 61 74 63 68 20 6f 66 20 63 6c 6f 73 65 22 0a catch of close".
0210: 20 20 20 20 20 20 20 20 70 75 74 73 20 73 74 64 puts std
0220: 65 72 72 20 22 5c 74 65 72 72 6f 72 43 6f 64 65 err "\terrorCode
0230: 3a 24 3a 3a 65 72 72 6f 72 43 6f 64 65 22 0a 20 :$::errorCode".
0240: 20 20 20 20 20 20 20 73 65 74 20 50 74 69 45 78 set PtiEx
0250: 65 63 28 46 69 6f 44 6f 6e 65 29 20 31 0a 20 20 ec(FioDone) 1.
0260: 20 20 7d 0a 7d 0a 23 0c 0a 0a 70 72 6f 63 20 70 }.}.#...proc p
0270: 74 69 54 6f 53 74 64 6f 75 74 20 7b 20 6c 69 6e tiToStdout { lin
0280: 65 20 7d 20 7b 0a 20 20 20 20 70 75 74 73 20 2d e } {. puts -
0290: 6e 6f 6e 65 77 6c 69 6e 65 20 22 3c 3c 24 6c 69 nonewline "<<$li
02a0: 6e 65 3e 3e 22 0a 20 20 20 20 66 6c 75 73 68 20 ne>>". flush
02b0: 73 74 64 6f 75 74 0a 7d 0a 0a 23 20 57 6f 72 6b stdout.}..# Work
02c0: 73 0a 70 72 6f 63 20 77 6f 72 6b 73 20 7b 20 7d s.proc works { }
02d0: 20 7b 0a 20 20 20 20 73 65 74 20 66 69 64 20 5b {. set fid [
02e0: 6f 70 65 6e 20 22 7c 63 68 69 6c 64 20 32 3e 40 open "|child 2>@
02f0: 73 74 64 65 72 72 22 20 72 5d 0a 0a 20 20 20 20 stderr" r]..
0300: 66 69 6c 65 65 76 65 6e 74 20 24 66 69 64 20 72 fileevent $fid r
0310: 65 61 64 61 62 6c 65 20 5b 6c 69 73 74 20 50 74 eadable [list Pt
0320: 69 45 78 65 63 52 65 61 64 52 65 73 75 6c 74 73 iExecReadResults
0330: 20 24 66 69 64 20 70 74 69 54 6f 53 74 64 6f 75 $fid ptiToStdou
0340: 74 5d 0a 20 20 20 20 76 77 61 69 74 20 3a 3a 50 t]. vwait ::P
0350: 74 69 45 78 65 63 28 46 69 6f 44 6f 6e 65 29 0a tiExec(FioDone).
0360: 0a 20 20 20 20 70 75 74 73 20 73 74 64 65 72 72 . puts stderr
0370: 20 22 50 74 69 45 78 65 63 28 46 69 6f 53 74 61 "PtiExec(FioSta
0380: 74 75 73 29 3a 24 3a 3a 50 74 69 45 78 65 63 28 tus):$::PtiExec(
0390: 46 69 6f 53 74 61 74 75 73 29 22 0a 7d 0a 0a 70 FioStatus)".}..p
03a0: 72 6f 63 20 66 61 69 6c 73 20 7b 20 7d 20 7b 0a roc fails { } {.
03b0: 20 20 20 20 73 65 74 20 66 69 64 20 5b 6f 70 65 set fid [ope
03c0: 6e 20 22 7c 63 68 69 6c 64 20 32 3e 40 73 74 64 n "|child 2>@std
03d0: 65 72 72 22 20 72 5d 0a 0a 20 20 20 20 66 63 6f err" r].. fco
03e0: 6e 66 69 67 75 72 65 20 24 66 69 64 20 2d 62 75 nfigure $fid -bu
03f0: 66 66 65 72 69 6e 67 20 6e 6f 6e 65 20 2d 62 6c ffering none -bl
0400: 6f 63 6b 69 6e 67 20 30 20 2d 74 72 61 6e 73 6c ocking 0 -transl
0410: 61 74 69 6f 6e 20 62 69 6e 61 72 79 0a 20 20 20 ation binary.
0420: 20 66 63 6f 6e 66 69 67 75 72 65 20 73 74 64 6f fconfigure stdo
0430: 75 74 20 2d 62 75 66 66 65 72 69 6e 67 20 6e 6f ut -buffering no
0440: 6e 65 20 2d 62 6c 6f 63 6b 69 6e 67 20 30 20 2d ne -blocking 0 -
0450: 74 72 61 6e 73 6c 61 74 69 6f 6e 20 62 69 6e 61 translation bina
0460: 72 79 0a 0a 20 20 20 20 66 69 6c 65 65 76 65 6e ry.. fileeven
0470: 74 20 24 66 69 64 20 72 65 61 64 61 62 6c 65 20 t $fid readable
0480: 5b 6c 69 73 74 20 50 74 69 45 78 65 63 52 65 61 [list PtiExecRea
0490: 64 52 65 73 75 6c 74 73 20 24 66 69 64 20 70 74 dResults $fid pt
04a0: 69 54 6f 53 74 64 6f 75 74 5d 0a 20 20 20 20 76 iToStdout]. v
04b0: 77 61 69 74 20 3a 3a 50 74 69 45 78 65 63 28 46 wait ::PtiExec(F
04c0: 69 6f 44 6f 6e 65 29 0a 0a 20 20 20 20 70 75 74 ioDone).. put
04d0: 73 20 73 74 64 65 72 72 20 22 50 74 69 45 78 65 s stderr "PtiExe
04e0: 63 28 46 69 6f 53 74 61 74 75 73 29 3a 24 3a 3a c(FioStatus):$::
04f0: 50 74 69 45 78 65 63 28 46 69 6f 53 74 61 74 75 PtiExec(FioStatu
0500: 73 29 22 0a 7d 0a 0a 0a 0a s)".}....