How to detect if a perforce session is opened?

孤人 提交于 2019-12-25 08:48:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!