2011-12-08

P4 and return codes

This just hit me.


>cat test.sh
#!/bin/sh
/usr/local/bin/p4 sync -n
rc=$?
echo "Returncode $rc"

>cat test2
#!/bin/sh
# \
exec tclsh "$0" "$@"
set rc [catch {exec -- /usr/local/bin/p4 sync -n} out]
puts "Return code: \"$rc\""
puts "out: \"$out\""


 >./test2
Return code: "1"
out: "File(s) up-to-date."

 >./test.sh
File(s) up-to-date.
Returncode 0

>/usr/local/bin/p4 sync -n
File(s) up-to-date.
>echo $?
0

>/usr/local/bin/p4 -s sync -n
error: File(s) up-to-date.
exit: 0

P4 knowledge base article regarding this:

"In general, you should not rely on a command exiting non-zero on "failure". Instead, use the global -s flag to help interpret the command output -- and parse that output in your scripts. Possible tags with the -s flag include info:, info1:, info2:, error:, and text:"

My kangaroo rating for this:
 [x] not funny!

No comments:

Post a Comment