How to call Batch file from TCL (Windows)

Clovertech Forums Read Only Archives Cloverleaf Tcl Library How to call Batch file from TCL (Windows)

  • Creator
    Topic
  • #54781
    Tauqirul Haque
    Participant

      Hi,

      How do we execute (call) a windows batch file from TCL as a different process.

      I am using the following code to call the batch file.

      [exec “C:/Windows/System32/cmd.exe /c $HciSiteDir/CreatePatientServiceJKS.bat $processName”]  

      Here:

      CreatePatientServiceJKS.bat is the batch file to be called.

      $processName is the argument to passed as an input to the batch file.

      Thanks in advance

      javascript:emoticon(‘:)’)

    Viewing 2 reply threads
    • Author
      Replies
      • #82968
        Charlie Bursell
        Participant

          The following file extensions can be executed directly from Tcl on Windows:

                         .exe, .com. and .bat

          Therefore you can execute without the /c option.  All that will do is call a subshell

          [exec “$HciSiteDir/CreatePatientServiceJKS.bat $processName”]  

          Even simpilar would be to create a scripts directory under the site.  You always have a path to $HciSiteDir/scripts in the environment.  Then your call becomes simply:   [exec CreatePatientServiceJKS $processName]

          Note even the .bat is not needed except to protect against ambiguity.  For instance if you had an executable like CreatePatientServiceJKS.exe in your path.  However, I doubt that   😀

        • #82969
          Jeff Dinsmore
          Participant

            Are you trying to start an independent, non-blocking, process for the bat file?

            If so, you can launch the exec as a background process that will fire the batch, then will return control immediately to Tcl – like this:

            Code:

            set execPid [exec “$HciSiteDir/CreatePatientServiceJKS.bat $processName” &]

            This starts the background process, stores the PID in execPid and immediately returns control to Tcl.

            From ActiveState’s exec manual page

            Code:

            If the last arg is “&” then the pipeline will be executed in background. In this case the exec command will return a list whose elements are the process identifiers for all of the subprocesses in the pipeline. The standard output from the last command in the pipeline will go to the application’s standard output if it hasn’t been redirected, and error output from all of the commands in the pipeline will go to the application’s standard error file unless redirected.

            Jeff Dinsmore
            Chesapeake Regional Healthcare

          • #82970
            Tauqirul Haque
            Participant

              @ Charlie and Jeff

              I wanted to execute a batch as a background process, as per your suggestion it worked.

              Thanks for your kind help 🙂

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