It was possible to create a bad ref
[jimtcl.git] / examples / popen.tcl
blob8a6b6e3178706ecbf2cfbafed6321945a5d2033f
1 # Internally, open "|..." calls out to popen from tclcompat.tcl
3 # This code is compatible with Tcl
5 # Write to a pipe
6 set f [open |[list cat | sed -e "s/line/This is line/" >temp.out] w]
7 foreach n {1 2 3 4 5} {
8 puts $f "line $n"
10 close $f
11 puts "Created temp.out"
13 # Read from a pipe
14 set f [open "|cat temp.out"]
15 while {[gets $f buf] >= 0} {
16 puts $buf
18 close $f
19 file delete temp.out