I am trying to run a csh script from a tcl script.
The tcl script below calls a 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 (begining of the) csh file is below:
#!/bin/csh -f
echo abcdefgh
When I only execute the csh file from my unix terminal, it works fine. When I call my Tcl script, it runs and indeed writes "hello" and prints i, but the csh file is not executed because "abcdefgh" never appears in the terminal. I have also tried other commands, and I always have the same problem: the csh script is never executed when I run it from a Tcl script, even though it runs fine when I run it directly from the terminal.
(Both my Tcl script ans csh script are executable)
What must I do in order to run my csh script from my Tcl script ?
Thank you very much
The csh script is indeed run for you, but by default its standard output becomes the result of the Tcl exec
command (and if it produced anything on standard error, that would become an error result of the exec
). To make the output and error appear on the terminal, you have to modify the exec
like this:
exec /bin/csh -c $synthesis >@stdout 2>@stderr
The >@
says “redirect standard output to the following channel” (stdout
in this case), and the 2>@
does the same for standard error.
来源:https://stackoverflow.com/questions/13341427/how-can-i-run-a-csh-script-from-a-tcl-script