Want to putll in an external file use it to pull data and throw the file out…

Clovertech Forums Cloverleaf Want to putll in an external file use it to pull data and throw the file out…

  • Creator
    Topic
  • #119430
    Tom Gilbert
    Participant

      I have a tcl proc that reads a file and processes it and sends it on it’s way. I want to put in a seperate file from within the tcl proc and disgard it when done. Here is what I have:

      set emailfilepath “/quovadx/cis5.8/integrator/kdtest_miln/files/infor_inscvg/temp/email_infor_inscvg.txt”

      set emailfile [open $emailfilepath r]

      close $emailfile

      Not giving me an error but does not seem to be opening the file.

    Viewing 7 reply threads
    • Author
      Replies
      • #119431
        Jim Kosloskey
        Participant

          Are you sure you want your access to be r? If the file does not exist, it will not create it.

          How are you determining the file is not being opened?

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #119432
          Tom Gilbert
          Participant

            Here is the value from echo below… ‘msg2 file6’ Not sure where file6 is coming from

            set emailfilepath “/quovadx/cis5.8/integrator/kdtest_miln/files/infor_inscvg/temp/email_infor_inscvg.txt”

            set msg2 [open $emailfilepath r]

            echo
            echo msg2 $msg2
            echo

          • #119433
            Jim Kosloskey
            Participant

              The open gives you a file handle that is what ‘file6’ is.

              Is this file supposed to already exist or are you creating it?

              email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

            • #119434
              Jeff Dinsmore
              Participant

                file6 is the file handle created by the open. It’s written into the msg2 variable by “set”

                If you want to read the content of the file, you’ll need to do that with read, gets, or something like that.

                For example, after opening the file for read you can read the whole file.

                set fileHandle [open $emailfilepath r]
                set wholeFile [read $fileHandle]
                close $fileHandle

                puts “content of file=$wholeFile”

                Jeff Dinsmore
                Chesapeake Regional Healthcare

              • #119435
                Tom Gilbert
                Participant

                  file already exists

                • #119436
                  Jim Kosloskey
                  Participant

                    So are you issuing a command like gets to actually read the file?

                    email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                  • #119437
                    Charlie Bursell
                    Participant

                      Jeff provided the definitive answer. However if you want this to be portable and error proof, you need something like:

                      set emailfilepath [file join ::$HciSiteDir files infor_inscvg temp email_infor_inscvg.txt]
                      if {[file exists $emailfilepath]} {
                      set fileHandle [open $emailfilepath r]
                      set wholeFile [read $fileHandle]
                      close $fileHandle
                      puts “content of file=$wholeFile”
                      } else {
                      puts “ERROR: $emailfilepath does not exist”
                      # Do error cleanup here
                      }

                    • #119439
                      Tom Gilbert
                      Participant

                        Hello Sir,

                        This worked perfectly…:)

                        set fileHandle [open $emailfilepath r]
                        set wholeFile [read $fileHandle]
                        close $fileHandle

                        Thank you…:)

                    Viewing 7 reply threads
                    • You must be logged in to reply to this topic.