tcl 脚本在 git bash 中出现 LF 警告后停止
我有以下脚本用于将文件添加到 git。 当我尝试运行脚本时,我使用 tclsh 在 git bash 上运行它
proc git_add {file_ext file_type folder} {
try {
set results [exec git add $file_ext]
} trap CHILDSTATUS {results options} {
puts "Warning: No $file_type files update has been found in $folder"
}
}
puts "Files will be added to git now "
set path "src"
cd $path
git_add "*.vhd" "Project" $path
git_add "*.v" "Project" $path
git_add "*.sv" "Project" $path
,如果文件有 LF 而不是 CRLF,它会发出警告并停止。
错误如下:
文件将立即添加到 git 警告:LF 将被 CRLF 替换 英特尔/fpgas/fpga_link2/rtl/prbstest.vhd。该文件将有其 工作目录中的原始行结尾。
执行“exec git add $file_ext”时
(过程“git_add”第 2 行)
从“git_add *.vhd”VHD”$path”中调用
如何解决这个问题?
I have the following script for adding files to git. I am running it on git bash using tclsh
proc git_add {file_ext file_type folder} {
try {
set results [exec git add $file_ext]
} trap CHILDSTATUS {results options} {
puts "Warning: No $file_type files update has been found in $folder"
}
}
puts "Files will be added to git now "
set path "src"
cd $path
git_add "*.vhd" "Project" $path
git_add "*.v" "Project" $path
git_add "*.sv" "Project" $path
when I try to run the script, if the a file has LF instead CRLF, it gives warning and it stops.
the error is as follow:
Files will be added to git now warning: LF will be replaced by CRLF in
intel/fpgas/fpga_link2/rtl/prbstest.vhd. The file will have its
original line endings in your working directory.while executing "exec git add $file_ext"
(procedure "git_add" line 2)
invoked from within "git_add *.vhd "VHD" $path"
How to fix that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,Tcl 将标准错误通道上的输出视为错误。 git 命令的警告很可能出现在 stderr 上。不幸的是,这种情况不会产生可以通过
try
命令捕获的有用错误代码。因此,您要么需要使用on error
子句捕获一般错误,要么将-ignorestderr
选项添加到exec
命令中以禁用此功能行为。By default, Tcl treats output on the standard error channel as an error. Most likely the warning from the git command appears on stderr. Unfortunately, such a case does not produce a useful error code that you can trap via the
try
command. So, either you need to catch general errors with anon error
clause, or you add the-ignorestderr
option to theexec
command to disable this behavior.exec
命令在两种情况下抛出错误:exec
捕获该错误。这是你遇到的第二个案例。您需要决定您希望通过该消息发生什么。
一种简单的选择是重定向它,以便用户可以在终端中看到它。
此(
2>@stderr
)将其重定向到 Tclstdout
通道(任何通道都可以,只要它具有操作系统文件描述符)。如果您使用
open |
启动管道并有权访问其输入和/或输出,则当您关闭
通道时会引发错误。exec
大约是这样的(除了更多的错误处理并且它是用 C 编写的):The
exec
command throws an error in two cases:exec
captures that.It's the second case that you're hitting. You need to decide what you want to happen with that message.
One easy option is to redirect it so that the user can see it in their terminal.
This (the
2>@stderr
) redirects it to the Tclstdout
channel (any channel will do provided it has an OS file descriptor).If you use
open |
to launch the pipeline and have access to its input and/or output, the errors are thrown when youclose
the channel.exec
is approximately this (except with more error handling and it is written in C):