tcl gets command

Clovertech Forums Read Only Archives Cloverleaf Tcl Library tcl gets command

  • Creator
    Topic
  • #50191
    Roman Partigula
    Participant

      Hi

      I have a question about gets tcl command

      I have a tcl script to search through SMAT files

      I use this code :


      set f [ open filename ]

      while { 1 } {

             set rc [ gets $f rec ]

             if { $rc< 0 } {break }                  puts $rec } close $f


      It works fine

      then I decided to use the same script to read input not from the file

      but from the pipe

      cat filename  | myscript  

      My code in this case :

      while { 1 } {

             set rc [ gets stdin rec ]

             if { $rc< 0 } {break }                  puts $rec }   I noticed in this case gets converts all r to n

      which is not the case when it reads from file

      Is it a way to control this behavior and disable this convertion?

      Thanks

    Viewing 0 reply threads
    • Author
      Replies
      • #65149

        Here are the notes I took while working on a similiar issue.

        Code:

        # tcl tmp.tcl tcl readFile.tcl tmp.hl7
        proc method1 {} {
           set f [open [lindex $argv 0]]
           set msg [read $f]
           close $f;
           puts $msg;
        }

        # > tcl readFile.tcl < tmp.hl7
        proc method2  {} {
           # By default, Tcl translates the Mac line separator r to the internal Tcl
           #    (and Unix) line separator n. This lines turns off the default behavior.
           fconfigure stdin -translation binary;
           set msg [read stdin]
           puts $msg
        }

        method1

        -- Max Drown (Infor)

    Viewing 0 reply threads
    • The forum ‘Tcl Library’ is closed to new topics and replies.