【发布时间】:2015-03-30 14:55:25
【问题描述】:
我有 2 个 procs,它们一个接一个地被调用。第一个过程使用diff 功能并创建file.txt。压缩文件后的proc。问题是当我运行脚本时,file.txt 是空的。当我注释掉压缩过程时,文件中印有差异。
我相信这是因为第二个 proc 没有等待第一个 proc 完成。
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。直到脚本结束,Differences 文件被创建,但它的大小是 0。
【问题讨论】:
-
创建差异后再次运行程序,但这次反转 cmets 以便 create_compress 运行。文件还是空白还是压缩成功了?
-
你如何使用差异?你能展示你如何从 Tcl 调用 diff 吗?
-
我应该编辑我的帖子,文件已压缩(压缩有效),但它是空的
-
这是一个语法错误:
puts $dso1 stderr "** diff exited with status $status **"--puts的参数数量错误 -
你没有后台进程,所以删除
wait