How to run csh script from tcl script?

I am trying to run csh script from tcl script.

Below tcl script is called csh script

#!/usr/bin/tclsh set scripts_path /scratch/TCL_scripts/scripts_adders set synthesis /scratch/TCL_scripts/synthesis.csh set files [glob -directory $scripts_path *] split $files set files [lsort $files] set i 1 foreach script $files { puts "hello" # puts [pwd] exec /bin/csh -c $synthesis puts $i } 

And the csh file (start) is below:

 #!/bin/csh -f echo abcdefgh 

When I execute only the csh file from my unix terminal, it works fine. When I invoke my Tcl script, it starts and really writes β€œhi” and prints i, but the csh file is not executed because β€œabcdefgh” never appears in the terminal. I also tried other commands, and I always had the same problem: csh script never runs when I run it from Tcl script, although it works fine when I run it directly from the terminal.

(And my Tcl script ans csh script executes)

What should I do to run my csh script from my Tcl script?

Thank you very much

+4
source share
1 answer

The csh script does run for you, but by default its standard output is the result of the Tcl exec command (and if it produces something on a standard error, it will result from the exec error). To make a conclusion and an error on the terminal, you must modify exec as follows:

 exec /bin/csh -c $synthesis >@stdout 2>@stderr 

>@ says "redirect standard output to the next channel" ( stdout in this case), and 2>@ does the same for the standard error.

+5
source

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


All Articles