[p4] Execute P4 command in CGI from within Apache Web server
Greg Pan
Greg.Pan at RealTimeEdge.ca
Thu Mar 29 10:14:28 PST 2007
I have a Python script which runs fine standalone. But it couldn't be
executed correctly when it's run as CGI within a Web server - Apache Web
server to be exact. The script lists the submitted changes in a
particular directory of depot. It seems to me that, when executed as CGI
from Web page, the stdout from the command is lost somehow. As a test -
if I changed the p4 user name in the Global Option to be a non-existent
user name, the stderr is piping back, printing out something like "
Access for user 'someone' has not been enabled by 'p4 protect'" in the
page.
For your reference I have the simplified code there. Can anyone help
please?
#!C:\python24\python.exe
import cgi, os, sys, string, re, time
debugFlag = True
def debug(msg):
""" Prints out debug messages according to the debugFlag setting """
if debugFlag:
print msg
def execute(cmd):
debug("cmd is %s" % cmd)
try:
output = os.popen4(cmd)
if not output[1]:
debug("Unable to run '%s'" % cmd)
return output[1]
except OSError, msg:
debug(msg)
if __name__ == '__main__':
cmd = "%s %s %s %s" % ("p4", "-ugpan", "changes", "//depot/dev/...")
print "Content-Type: text/html"
print
print '<html><body>'
lines = execute(cmd).readlines()
for i in range(0, len(lines), 1) :
debug("line is %s" % lines[i])
print '</body></html>'
Thanks,
Greg
More information about the perforce-user
mailing list