I have 2 procs which are called one after the other. The first proc uses the diff
functionality and creates file.txt
. The proc right after compresses the file. The issue is that when I run the script, the file.txt is empty. When I comment out the compressing proc, the file has the differences printed in it.
I believe this is caused because the second proc does not wait for the first proc to finish.
create_difference "file1" "file2"
create_compress "path"
The order of procedure calls above produce an empty file.txt.gz
create_difference "file1" "file2"
#create_compress "path"
The order of procedure calls above create an expected difference file. Within the procs, I tried adding a return statement (to return 1), this did not make a difference.
I tried using the wait
command as in Waiting for background processes to finish before exiting script:
create_difference "file1" "file2"
wait
create_compress "path"
However the script hangs at that point.
Proc for creating the differences: 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 "***********************************************************************"
}
The proc for compressing the files:
proc create_compress {thepath} {
catch {exec find ${thepath}/. -type f -exec gzip "{}" \; } result
#return 1
}
There are some other files in there which need compressing, which is why I compress every file within the folder, given the path of the folder. The other files do compress as intended.
I ran some more testing on it. It seems that even after the diff proc has been called and finished, the differences are written to file.txt ONLY after the script has ended. Right up to the end of the script, the Differences file is created, but it's size is 0.
puts $dso1 stderr "** diff exited with status $status **"
-- wrong number of arguments forputs
– glenn jackmanwait
– glenn jackman