Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Using the P4 module through Apache

by fatherlyons (Initiate)
on Jun 30, 2005 at 13:22 UTC ( [id://471303]=perlquestion: print w/replies, xml ) Need Help??

fatherlyons has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I have a script which uses the P4 module to connect to a Perforce server, perform some simple P4 commands and write the results to a text file. The script works fine when I run it as a standalone script but when I run it as a perl process from an Apache server it doesn't give me any output in the text file. I'm probably doing something really stupidly wrong here so any help will be appreciated. Cheers. DP

Replies are listed 'Best First'.
Re: Using the P4 module through Apache
by sk (Curate) on Jun 30, 2005 at 13:57 UTC
    Can you please post your code snippet so that we can see what is wrong?

    Some pointers will be helpful

    1. are you running mod_perl (version)?

    2. Does the apache have write permission on the directory you are using?

    3. If you use open (something) or die ; what do you get in your apache error log?

    cheers

    SK

      OK, heres my bit of code. I don't think it's anything to do with write access to the text file as the script successfully prints "Test" to the file. However, for some reason it does not print the contents of the @info array..
      use P4; open OUTFILE, ">.\\Testing.txt"; my $p4 = new P4; $p4->SetClient( "my-client" ); $p4->SetPort ( "Perforce01:xxxx" ); $p4->SetPassword( "my-password" ); $p4->Init() or die( "Failed to connect to Perforce Server" ); $p4->Login(); my $command = "describe"; my @options; push @options, "-s", "577536"; my @info = $p4->Run( $command, @options ); my @errors = $p4->Errors(); $p4->Disconnect(); foreach my $line (@info) { print OUTFILE $line; } print OUTFILE "Test"; close OUTFILE;
        I am not familiar with P4 module but here are some "have you tried(s)" -

        1. I see you are getting results into errors array but dont' check if there are errors. Can you check the length of this array?

        2. Is it possible that @info does not contain any elements?

        3. Can you print the resuls to the browser instead of text file so that you can verify the problem is not with Apache?

        cheers

        SK

Re: Using the P4 module through Apache
by rev_1318 (Chaplain) on Jun 30, 2005 at 13:58 UTC
    Without knowing your code I have to guess: permissions or path problem...
    are you using a relative path for the file to write to? Bear in mind that the working directory of your apache process (CGI script?) will be different then when you run the program standalone. Also, the credentials (user) will be different, so maybe the proces has no rights to write the file.

    Have you checked the apache logs for errors?

    Paul

Re: Using the P4 module through Apache
by etcshadow (Priest) on Jun 30, 2005 at 18:54 UTC
    The perforce client inherits a lot of stuff (such as the username) from the shell's environment. When you run something in apache, you probably need to set those environment variables first. You can do that by just:
    $ENV{P4USER} = 'foo';
    and so on. Also, I think you can set those things explicitly on the $p4 object before you ->Login().
    ------------ :Wq Not an editor command: Wq

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://471303]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-16 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found