Can TCL call a command from command line?

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Can TCL call a command from command line?

  • Creator
    Topic
  • #49856
    Deanna Norman
    Participant

      Can TCL call a command from command line?

      As it states…

      Thanks,

    Viewing 2 reply threads
    • Author
      Replies
      • #63885
        Mark McDaid
        Participant

          Yes, you use the exec command.  It’s best to enclose it inside a catch command in case it errors out.  Here’s an example from some tcl code that I have to create a 10 second delay within a loop:

          catch {exec ping 127.0.0.1 -n 10 -w 1000 > nul} err

          Hope that helps.

        • #63886
          Russ Ross
          Participant

            Soemtimes you will run into the case where exec will be stubborn about running a particular command line for you.

            If that happens you might also try using the system command in TCL.

            Here is a snippet that shows a working example of the TCL system command from wihtin one of our TCL procs that calls a command line utility (sendmail) to send an email typically to a pager in our case:

                system “touch ../../../Alerts/$HciConnName.off”

            Here is a snippet we use that stops a given thread

                system “hcicmd -p $process -c “$HciConnName pstop””

            Russ Ross
            RussRoss318@gmail.com

          • #63887
            David Barr
            Participant

              I be careful with using “system”.  Cloverleaf sets up the standard output and standard error channels kind of strangely.  When an engine process is run, the Tcl “stdout” and “stderr” channels are redirected to the process log file, but the Unix stdout and stderr file descriptors don’t go to the log file.  If you run a subprocess with either exec or system, the output of the process won’t normally go to the process log file.  If you use exec, you can include “>&@ stdout” in your command to have the output go to the log file.  I haven’t found a similar solution for the system command.

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