gpt4 book ai didi

linux - TCL 在 proc 之后调用另一个 proc

转载 作者:太空宇宙 更新时间:2023-11-04 10:54:33 26 4
gpt4 key购买 nike

我有 2 个过程,它们一个接一个地调用。第一个过程使用 diff 功能并创建 file.txt。压缩文件后的过程。问题是当我运行脚本时,file.txt 是空的。当我注释掉压缩过程时,文件中打印了差异。我相信这是因为第二个过程没有等待第一个过程完成。

create_difference "file1" "file2" 
create_compress "path"

上面的过程调用顺序产生一个空文件.txt.gz

create_difference "file1" "file2" 
#create_compress "path"

上面的过程调用顺序创建了一个预期的差异文件。在 procs 中,我尝试添加一个 return 语句(返回 1),这没有什么区别。

我尝试使用 wait 命令,如 Waiting for background processes to finish before exiting script :

create_difference "file1" "file2" 
wait
create_compress "path"

但是脚本在那一刻挂起。

创建差异的过程:tcl: capture output from "exec diff" which returned non-zero

set dso1 [open file.txt w]
set status [catch {exec diff $file1 $file2} result]
if {$status == 0} {
puts $dso1 "$file1 and $file2 are identical"
} elseif {$status == 1} {
puts $dso1 "** $file1 and $file2 are different **"
puts $dso1 "***************************************************************************"
puts $dso1 ""
puts $dso1 $result
puts $dso1 ""
puts $dso1 "***************************************************************************"
} else {
puts stderr "** diff exited with status $status **"
puts stderr "***********************************************************************"
puts stderr $result
puts stderr "***********************************************************************"
}

压缩文件的过程:

proc create_compress  {thepath} {
catch {exec find ${thepath}/. -type f -exec gzip "{}" \; } result
#return 1
}

那里还有一些其他文件需要压缩,这就是为什么我压缩文件夹中的每个文件,给定文件夹的路径。其他文件按预期压缩。

我对其进行了更多测试。似乎即使在调用并完成 diff proc 之后,差异也会在脚本结束后写入 file.txt。一直到脚本末尾,都会创建差异文件,但它的大小为 0。

最佳答案

差异文件没有被写入的原因是它没有关闭。在我的 create_diff 过程中,我忘记包含命令:close $dso1因此,一旦脚本运行完毕,它才会写入文件。但是,在 diff proc 之后,我立即压缩了文件,由于它无法写入压缩文件,因此该文件将为空。

长长的;我没有关闭正在写入差异的文件。

关于linux - TCL 在 proc 之后调用另一个 proc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29349478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com