[p4] Help

Weintraub, David david.weintraub at bofasecurities.com
Fri Jun 23 06:04:21 PDT 2006


Sudip:

Triggers in Perforce are executed on the server, and only on the server.
This can make writing the trigger a bit easier since the trigger doesn't
have to work on all systems. For example, you might prefer to write your
trigger in Python, Perl, or even Bourne shell scripting.  Triggers can
be written in Java too, but since Java involves compiling code, most
people avoid it for writing triggers. 

The trigger, by the way, inherits the environment of the server task, so
any environment variables defined when the server task starts up are
inherited by the trigger. I take advantage of this by making sure that
my environment is setup the way I want it when the server runs. For
example, I make sure that $PATH and $P4CONFIG are set to the correct
values. Some people have a non-expiring ticket and set $P4TICKET to
point to this ticket. That way, triggers don't fail due to login
problems.

Another hint is that Perforce prints out STDOUT only when a trigger
fails, and not STDERR. That means if Perforce is generating an error
message, you won't see it when your trigger fails. For example, if the
trigger is running in an environment where the ticket file has expired,
you won't see the not logged in error message. Most people get around
this by redirecting STDERR to STDIN (using the 2>&1 shell syntax) when
defining their triggers. 

Another problem with Perforce is that Perforce commands don't return
non-zero error codes when a command ...uh... "fails". For example, if I
do a grep on a file, and the file doesn't contain the regular expression
I'm grepping for, grep returns an exit status of 2. When you use "p4"
commands, they will return an exit code of "0" even if they didn't work
as you expected. For example, doing a "p4 file //depot/foo when there is
no //depot/foo will return an error code of "0". And, if you attempt to
run a "p4" command, and you're not logged into Perforce, that command
still returns an error code of "0".

The gist of this is that you can't trap for errors when using the
"system" command in Java. There are many times in my Perl code I do
something like this:

$error = system("p4 $cmd");
if ($error) {
   die "Can't execute p4 $cmd"\n);
}

And discovering that "p4 $cmd" didn't run, but that my program continued
executing anyway. Usually, somewhere farther down the line, my program
will finally error out, but with a completely different error message
than what originally caused the problem. What I am left with is
attempting to debug the program with a very confusing error message.

When I write a trigger, I put debugging code in my trigger script. A
typical trigger (I tend to write them in Perl) will looks something like
this for me:

========
*DEBUG = \0;
   our $DEBUG;
[...]

sub debug {
    my $message = $_[0];
    if ($DEBUG) {
        print STDOUT "DEBUG: $message\n";
    }
}

[...]
debug ("I just did this");
[...]
debug ("I just did that");
[...]

#
#    ####End of Trigger
#

Print "The trigger worked!\n";
exit $DEBUG;
====================

This way, I can quickly debug the trigger by simply changing the value
of $DEBUG at the beginning of my program to "2". Changing the value of
DEBUG to a non-zero value prints out all of my debug statements and
guarantees that the trigger will fail.

I wish I can tell you more than this, but without more details, I can't
really know where you might look. I hope this is enough information to
help you get started.

-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of Sudip Sen
Sent: Friday, June 23, 2006 4:35 AM
To: perforce-user at perforce.com
Subject: [p4] Help

Dear All users,

My name is Sudip Sen and I am trying to integrate perforce with my own
software. Our software is running in windows and the client has their
perforce server in linux. So i am using java files to integrate perforce
with our software. We are using p4.jar file.

The problem is when we are submitting the job, in the trigger i am
calling the java file. Now first I have created Env class object. This
is creating successfully. but after that when i am passing this env as a
parameter in creating the Job class or p4Process class then I am getting
an error said "P4 not found".

Can you help me in this matter. This is very important to me and urgent
also.

Waiting for your answer.

Please kindly send me as soon as possible.

Regards,

Sudip Sen

_______________________________________________
perforce-user mailing list  -  perforce-user at perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user


More information about the perforce-user mailing list