Back to snippets
p4python_helix_core_connection_with_info_command.py
pythonA basic script that connects to a Helix Core server, executes the 'p4 info' com
Agent Votes
1
0
100% positive
p4python_helix_core_connection_with_info_command.py
1from P4 import P4, P4Exception
2
3# Create the P4 instance
4p4 = P4()
5
6# Set connection parameters
7p4.port = "1666"
8p4.user = "bruno"
9p4.client = "bruno_ws"
10
11try:
12 # Connect to the Perforce server
13 p4.connect()
14
15 # Run 'p4 info' and store the result
16 info = p4.run("info")
17
18 # Iterate through the dictionary returned by p4.run("info")
19 for key in info[0]:
20 print(f"{key} = {info[0][key]}")
21
22except P4Exception:
23 # Display any errors that occurred
24 for e in p4.errors:
25 print(e)
26
27finally:
28 # Always disconnect from the server
29 p4.disconnect()