[p4] P4V - Problem using custom tools $c argument variable when no workspace selected
Roy Paterson
roy at smartbear.com
Fri May 2 11:30:59 PDT 2008
I'm having a problem using the Custom Tools $c (Current Workspace)
argument variable.
I have a Custom Tool specification that looks like this:
Application: mytool.exe
Arguments: --p4client $c --otherOption foo
If my current workspace is, say, MyWorkspace, then this results in
mytool.exe being invoked with 4 arguments:
1) --p4client
2) MyWorkspace
3) --otherOption
4) foo
This works fine but runs in to a problem when the user opens P4V and
doesn't specify a workspace. Then mytool.exe is invoked with 3 arguments:
1) --p4client
2) --otherOption
3) foo
This is problematic because now mytool.exe doesn't parse the arguments
correctly - it was expecting 4 arguments and now only has 3. So I tried
changing the Custom Tool arguments specification:
Arguments: --p4client "$c" --otherOption foo
This results in mytool.exe being invoked with arguments:
1) --p4client
2) "$c\
3) --otherOption
4) foo
... in other words if you surround $c directly with quotes then the $c
variable does not get replaced, and for some reason the second quote is
replaced with a \. I've tried all the combinations of quotes, escaping
quotes, etc... that I can think of, and I've only found one thing that
will work, but it looks really ugly. If you have at least one space
within the quotes between the $c and anything else, then it DOES get
replaced. So for example:
Arguments: --p4client "myEmptyArgumentPrefix $c myEmptyArgumentSuffix"
--otherOption foo
If the current workspace is not specified then this results in
mytool.exe being invoked with:
1) --p4client
2) myEmptyArgumentPrefix myEmptyArgumentSuffix
3) --otherOption
4) foo
If the current workspace is MyWorkspace then this results in mytool.exe
being invoked with:
1) --p4client
2) myEmptyArgumentPrefix MyWorkspace myEmptyArgumentSuffix
3) --otherOption
4) foo
Then to complete the workaround mytool.exe will parse argument #2 - if
it starts with "myEmptyArgumentPrefix " and ends with "
myEmptyArgumentSuffix" then I strip those off and end up with argument
#2 = MyWorkspace.
... So this works, but it's a really ugly hack. Can someone suggest a
better way to do this? Note that I cannot require that $c be the last
argument to mytool.exe.
Thanks,
Roy Paterson
Smart Bear Software
More information about the perforce-user
mailing list