[p4] Scripting with perforce, pitafalls ...

Nittin chawala nittinchawala at yahoo.co.in
Mon Mar 3 04:07:58 PST 2008

Yes so better to check for command success pattern instead of error .
  About exit status P4 always have been returning 0, i recently filed a enhancement request with P4 on this, ideally they should have returned non-zero exit status for failed commands.
Ildefonzo Arocha <ilde.web at gmail.com> wrote:
  Hello Perforcers,

Is it me or does anyone else find that even for the simplest task,
scripts have to handle and validate a lot of possible errors/warnings.

I am relatively new with Perforce. In the last months I have been
developing some administrative and end-users scripts. It has been a
challange though, no matter what I do, there is always some little
detail that makes my scripts fail.

On some situations some warnings are sent out as information messages
so parsing the output for "error" is not possible, same examples:

> p4 -s add -n project.r
error: project.r - protected namespace - access denied.
exit: 0
==> OK

> p4 -s add project.xml
error: project.xml - file(s) not in client view.
exit: 0
==> OK

> p4 -s add -n test.p
info: //xp/i2/main/ui/test.p#1 - opened for add
info1: //xp/i2/main/ui/test.p - also opened by iar at main
exit: 0
==> Not Ok?

> p4 -s add test.p
info: //xp/i2/main/ui/test.p#1 - currently opened for add
exit: 0
==> Not Ok?

> p4 -s add -n ui/polylayout/LayoutLL/aadtgend02.lst
info: //xp/i2/main/ui/polylayout/LayoutLL/aadtgend02.lst - can't add
existing file
exit: 0
==> Not Ok?

> p4 -s edit -n ui/polylayout/LayoutLL/aadtgend02.lst
info: //xp/i2/main/ui/polylayout/LayoutLL/aadtgend02.lst - can't edit
exclusive file already opened
info1: //xp/i2/main/ui/polylayout/LayoutLL/aadtgend02.lst - also
opened by vim at main
exit: 0
==> Not OK?

> p4 -s sync -n
error: File(s) up-to-date.
exit: 0
==> Not OK?

I have had several different situations, can't remember them all, the
most recent had to do with a script the performs a "intergrate -n -b
..." to list all missing revisions from a branch to another. I
inadvertively changed something in the Protection Table, the script
then returned no results. After some digging around I found out that:

> p4 -s -c "batch" integrate -n -r -b B_PRA
error: No permission for operation on file(s).
exit: 0
==> OK, interpret as an error

> p4 -s integrate -n -b B_5.01.04 -s "//xp/i2/main/ui/... at 19026, at 19026"
error: //xp/i2/main/ui/... at 19026, at 19026 - all revision(s) already integrated.
exit: 0
==> Arguably I wouldn't consider this an error, but is this behaviour

This last one is quite contradicting, you can argue that the
"integrate" command was not succesful hence "error" but then on the
examples above ("p4add" and "p4 edit") the commands are not succesful
either, however it outputs "info".

Because of this, I have been in the need to send the output of each p4
command to some temporal file, analyze it for info messages and error
messages and selectively ignore what is error and what is not. Hard
coding error messages in a script is not something I like to do, and
since I don't know in advance all possible message combination, I have
to do corrections on the scripts upon users feedback. A major
annoyance, not to mention unproductive.

Thoughts anyone?

perforce-user mailing list - perforce-user at perforce.com

 Bring your gang together - do your thing.  Start your group.

More information about the perforce-user mailing list