Does anyone knows how to use grep()
command in P4Python?
I am developing an script that runs with Perforce and makes it easy for me to search for specific texts inside multiple files.
I already tried to create a tool in Perforce > Tools > Manage Custom Tools using P4 commands like p4 grep -n -B 1 -e text_searched %D
but since I want to make the same search in multiple files, it will not work.
I've searched in P4 grep documentation and P4Python APIs for Scripting but I could not find how to do this.
I've noticed that some commands you can use run_commandName
, like:
from P4 import sys, P4, P4Exception
p4 = P4()
p4.run_integrated(fileName)
And it works really well! But I cannot use P4().run_grep()
=/
So, what I am trying to do is making a P4Python script. On Perfoce I made a Custom Toll like this:
Arguments: C:\Users\hmunguba\Projects\P4\scripts\searchp4pythonscript.py $u $p $c %D
And my code is something like:
from P4 import sys, P4, P4Exception
p4 = P4()
p4.user = sys.argv[1]
p4.port = sys.argv[2]
p4.client = sys.argv[3]
p4.connect()
FILE = str(sys.argv[4])
SEARCH_TEXT = sys.argv[5]
try:
p4.run("grep", "-e ", SEARCH_TEXT, FILE)
except P4Exception:
for e in p4.errors:
print e
finally:
p4.disconnect()
But the answer I get from this is always a blank screen. Can anyone help me with it?