更新时间:1970-01-01 07:56:42
csh脚本确实是为您运行,但默认情况下,其标准输出为Tcl exec
命令的 result (如果它在标准错误下产生了任何结果,成为 exec
的错误结果。为了使输出和错误出现在终端上,您必须像这样修改 exec
:
exec / bin / csh -c $ synthesis> @stdout 2> @stderr
> @
说将标准输出重定向到以下通道(在这种情况下为 stdout
),而 2> @
对于标准错误也是如此。
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.