Call bash script from tcl script and return and exit

I am trying to call a bash script from a TCL script and should get the exit status from the bash script or at least pass something back to the TCL script so that I can tell if my script has successfully completed. Any suggestions?

+6
source share
3 answers

See http://wiki.tcl.tk/exec - click the "Show discussion" button - there is a very detailed example of how to do this, I ask again. However you need to catch

 set status [catch {exec script.bash} output] if {$status == 0} { puts "script exited normally (exit status 0) and wrote nothing to stderr" } elseif {$::errorCode eq "NONE"} { puts "script exited normally (exit status 0) but wrote something to stderr which is in $output" } elseif {[lindex $::errorCode 0] eq "CHILDSTATUS"} { puts "script exited with status [lindex $::errorCode end]." } else ... 
+9
source

You want exec , the result of which will be in the return value, be warned, however there are many corrections using exec, in particular if you need to do some complicated quoting

+1
source

My experience in tcl is limited to random activities. However, the following links starting with the answer in @jk's answer led me to this page , which discusses the errorCode variable and related things that may be useful for this circumstance. Here is a brief example demonstrating the use of errorCode:

TCL:

 set ret_val [catch { exec /bin/bash /path/to/bash_script }] set errc $errorCode set ret_val [lindex [split $errc " " ] 2] puts $ret_val 

bash_script as above:

 #!/bin/bash exit 42 

which led to the exit:

42

+1
source

Source: https://habr.com/ru/post/895759/


All Articles