P4Python and global parameters: -d
I'm trying to create a workspace with P4 for Python. Command that works in terminal:
p4 -d path client -S //stream name
do not work in P4 version:
p4.run('-d', path, 'client', '-S', //stream, name)
I'm getting "[Error]: "Unknown command. Try 'p4 help' for info."". I've also tried:
self.p4.protocol("-d", path)
p4.run_client('-S', //stream, name)
It does not produce this error but the "-d" part has no effect. I've also tried quotations, with the same result. Why does it not run? How to use it?
Solution 1:
When you run a p4 command, the flags that come before the command name (the "global options") are flags to the CLI client itself, and the flags that come after the command are flags to the server command.
The p4.run
function sends a command directly to the server without invoking the p4
CLI, so the CLI options won't work (the server doesn't implement them at all so it'll just return a usage error). If you're trying to get the effect of one of the global options, there'll be an API function that has that effect.
For example, the P4Python equivalent of -d
is the cwd
property:
https://www.perforce.com/manuals/p4python/Content/P4Python/python.p4.html#Instance_Attributes_..37
so instead of:
p4.connect()
p4.run('-d', path, 'client', '-S', //stream, name)
do:
p4.cwd = path
p4.connect()
p4.run('client', '-S', //stream, name)