问题
I need to detect if a batch file has been executed from the local shell or by double-clicking within P4V. Is there a way I could check if P4V is open?
At first I thought to do it in this way, but as always, TIMTOWTDI. Any thoughts?
回答1:
Short answer: no, not really.
Long answer:
You can try to fake it, as you suggest, by checking for a running p4v.exe process. This will only tell you if P4V is open, though. If you had P4V open in another window, and you ran your batch file from a shell (e.g. double clicking in Explorer, or running it from a cmd prompt), you'll get a false positive.
Another approach you might take would be determining whether the script is within a Perforce client workspace. That could potentially be done by having the script run a "p4 where" on its own path to see if it's within the workspace -- but it depends on the script's executing environment having correct connection settings, which depends on the client machine being configured "nicely" (e.g. with P4CONFIG files and/or "p4 set", which are accessible to all Perforce client apps -- if you use P4V exclusively its connection settings won't be readily accessible to your script).
来源:https://stackoverflow.com/questions/46156741/how-to-detect-if-a-perforce-session-is-opened