I am banging my head on something that looks trivial. No doubt you'll
be able to help me :-)
exec diff.exe .\\v1\\$f1 .\\v2\\$f1 >${f1}_diff.txt
(running under windows XP hence the \\)
Looks simple. It is actually executed in a glob loop and it works as
expected, *but* it stops with a "child process exited abnormally" error
on the first files that are different.
Using -ignorestderr or catch doesn't help (it's not an error caught by
the OS, it is a return code from the diff.exe utility).
Thanks a pile in advance,
Bert
You can use / on windows instead of \\, too.
| Looks simple. It is actually executed in a glob loop and it works as
| expected, *but* it stops with a "child process exited abnormally"
| error on the first files that are different.
| Using -ignorestderr or catch doesn't help (it's not an error caught by
| the OS, it is a return code from the diff.exe utility).
You gave the explanation already: 'diff' exits non-zero if differences
are found, but a non-zero exit code is an indication of failure for TCL.
The solution is quite simple:
- catch the exec and inspect the errorCode in case of errors:
if {[catch {exec diff file1 file2 ...} err]} {
switch -- [lindex $::errorCode 0] {
CHILDSTATUS {
# error triggered by non-zero exit status
set status [lindex $::errorCode 2]
# status == 1 => files differ, everything else indicates a
# different error (file not found etc)
}
default {
# other error from 'exec'
}
}
}
HTH
R'
foreach f [glob src_v1/*] {
set f1 [file tail $f]
catch [exec diff.exe .\\src_v1\\$f1 ..\\Src\\$f1 >${f1}_diff.txt] err
}
I don't care about the return code at all so I'm not interested in
anything catch would be catching. I just want this script to _not_ stop
with the "child exited..." error.
Any idea ?
Ralf Fassel avait énoncé :
Try:
foreach f [glob src_v1/*] {
set f1 [file tail $f]
catch {
exec diff.exe .\\src_v1\\$f1 ..\\Src\\$f1 >${f1}_diff.txt
} err
}
The way you had it, was wrong: you were catching the _result_ of the
[exec] statement,
due to the square brackets.
Regards,
Arjen
catch { exec diff.exe .\\v1\\$f1 ..\\v2\\$f1 >${f1}_diff.txt }
_does_ work.
As correctly stated by the 2 OPs, my error was using [] instead of {}
(which doesn't prevent the $ substitution) !
THANKS A PILE !
Bert_Paris wrote :
Indeed. So far so good.
> (which doesn't prevent the $ substitution) !
But, the $ substitution wasn't your problem! It seems like you're
now mixing up [] with "", where $-subst would indeed have been a problem.
Try this simplified but diagnose-enhanced variant of your situation:
proc testcmd {} { puts "called testcmd"; return 42 }
proc testcatch {arg} {
puts "called testcatch with command: >>>$arg<<<"
puts "code: [catch $arg msg]\n retval or error: $msg"
}
testcatch [ testcmd ]
testcatch { testcmd }
# hint: copy&paste the procs en bloc, then the tests line by line.