Passing Linux variables to TCL

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Passing Linux variables to TCL

  • Creator
    Topic
  • #53097
    Skip Williams
    Participant

      Hello,

      I am using a tcl proc to pass arguements to a Linux script, query a SQL database and put the results of the query into a variable called orderNum.

      When I run the tcl proc from the engine testing tool, the echo from the Linux script provides the correct data, but the data is not passed back to the tcl proc.  I need to pass it back to a variable so I can insert the order number into a related result message.  Can someone help me understand how to set up the globals so this will work.  Here is a snippet of the tcl proc, copies of the Linux scripts that are called and the output from the testing tool:

      getOrdNumFromSQL.tcl:

      set orderNum [exec /home/hci/scripts/ordNumFromSQL.sh $msgDate $patLast $patFirst $patMid $patDOB $patGender $patSSN $ordDoc $resDesc]

      echo “orderNum from ordNumFromSQL.tcl proc:  $orderNum”

      ordNumFromSQL.sh:

      #!/bin/sh

      tcl /home/hcitest/scripts/ordNumFromSQL.tcl $1 $2 $3 $4 $5 $6 $7 $8

    Viewing 4 reply threads
    • Author
      Replies
      • #76549
        David Barr
        Participant

          I think you need to read and parse standard output of your script. Checking the return code will only give you a number indicating success or failure. You can do something like

          Code:

          set fp [open “|/home/hci/scripts/ordNumFromSQL.sh” r]
          set ordernum [gets $fp]

          You have to make sure that ordernum is the only thing that is echoed to stdout from the script. You can print debug messages to stderr if necessary.

        • #76550
          Skip Williams
          Participant

            I appreciate your response.  I am not sure what I doing here, but went ahead and inserted the suggested code.  I think we are opening a channel and piping the value from the query to the variable fp.  There were no errors but the result was not what we hoped for:

            ordernum was blank

            when I did an echo with $fp:  fp = file4

          • #76551
            David Barr
            Participant

              fp is a file handle that can read the output of the command. Each time you call “gets” on the handle you get one line of output from your script. This is sort of a clunky way to pass data from a shell script back to a TCL script.

              I’m a little confused why you don’t put everything into a proc, call mktclindex to get it added to your path and then call the proc directly rather than using exec and a shell script.

            • #76552
              Skip Williams
              Participant

                Good morning David,

                I know this thing looks pretty weird locgically.  My manager has asked me to insert data from an order message into a SQL table and then later, when the results are returned, to query the table and get the order number to add back into the result message.  The outpatient syatem will not post results without an order number, and the HIS, Meditech, does not send the order number back with the result.

                The health care system I work for decided not to buy the ODBC module for Cloverleaf, so I am trying to do this using Unix ODBC.  I have been able to successfully insert data into an orders table and pull the order number back out in a query, all within a Unix script.  But I can’t get the order number back to the cloverleaf environment so I can use it.

                I think what you have suggested will work but I think the tcl environment and the ksh shell are stepping all over each other.  So I am having a hard time putting this last part together.

                Thanks again for your help and I welcome further suggestions.  I have gotten so deep into this that I can’t see my way out especially with my limited Unix skills 😀

                Skip

              • #76553
                Skip Williams
                Participant

                  Finally got it.   I used your suggestion David, but could not mix tcl and the ksh shell.  So wrote the order number to a file using the shell, then used tcl to open the file “set fp [open $fullpath r]” and retrieve it.  Seems like it would have been a lot easier to pay Meditech to map the order number to a field in the result message, huh 😀

              Viewing 4 reply threads
              • The forum ‘Cloverleaf’ is closed to new topics and replies.