Trying to write out a file.

Clovertech Forums Read Only Archives Cloverleaf Tcl Library Trying to write out a file.

  • Creator
    Topic
  • #54463
    Mike Campbell
    Participant

      Cloverleaf 6.0.2 on AIX.

      I have a tcl proc that I’m passing a couple of data elements to that writes out to an external file.

    Viewing 3 reply threads
    • Author
      Replies
      • #81592
        Terry Kellum
        Participant

          Until you close the file, its probably sitting in a buffer.

        • #81593
          Elisha Gould
          Participant

            If the file is left open, use flush and have a close in the shutdown mode.

            Otherwise use close

            Code:

            set fileId [ open /quovadx/cis6.0/integrator/cl_test/exec/processes/ORM/TEMP_FILE_WITH_MRN.txt a+ ]
            .
            .
            .
            puts $fileId “$message_id $mrn”
            flush $fileId
            .
            .
            .
            close $fileId


            OR

            Code:

            set fileId [ open /quovadx/cis6.0/integrator/cl_test/exec/processes/ORM/TEMP_FILE_WITH_MRN.txt a+ ]
            puts $fileId “$message_id $mrn”
            close $fileId

            Would also probably be better to use the HCISITEDIR environment variable rather than using the full path. ie:

            Code:

            global env
            $env(HCISITEDIR)/exec/processes/ORM/TEMP_FILE_WITH_MRN.txt

          • #81594
            Charlie Bursell
            Participant

              You can use the flush command.   flush $fileId

              As Elisha said you should *NEVER* hard code a path inside the Cloverleaf root.  When you upgrade, the path is not valid for the new root.  Hard coded paths are the most insiduous thing we encounter when migrating because the path will still be vaild until you remove the old root.    Sometimes these hard coded paths can be hard to find.

              If you use the env array as suggested you either have to declare it as a global as Elisha showed or use the whole path like $::env(HCISITEDIR), etc.

              There are already existing globals for this purpose like $HciRoot, $HciSiteDir, etc.  If use use either of those you have to follow the same rule as bove for the env array.  You can see the list of Hci Globals with the Tcl command “info globals Hci*”.

              Since this file is in your process directory and the engine always runs in the process directory you could also do something like:

              set fileId [open [file join [pwd] TEMP_FILE_WITH_MRN.txt] a+ ]

              Note the pwd command returns the currect directory which will be the process directory when the engine is running.

              I usually prefer the file join command when building paths as it will always insert the correct path separators.

              Lots of ways to do the same thing.  Just a matter of preference   🙂

            • #81595
              Mike Campbell
              Participant

                Thanks all.  I added the join pwd and a close fileId and that works like advertised.

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