我們有一個系統在其某些路徑名中包含空格。由於他們是核心代碼的一部分,他們不能被重命名。在調用命令行命令的工具中處理這個問題只是增加一組雙引號。處理xml接口參數中的空格傳遞
但是,我還沒有找到一種方法來處理這個由Build Forge適配器使用的xml代碼。
例如,嘗試有適配器執行以下命令時:
cleartool describe "foo bar"@@\main\1
代碼想以下:
<match pattern="^(.*?)\@\@(.*?)$">
<run command="cc_describe" params="$1 $2"/>
<command name="cc_describe">
<execute>
pushd cleartool desc [email protected]@$2;
</execute>
</command>
假定$ 1 = 「富欄」 和$ 2 =「 \ main \ 1「
在執行時,第二個參數當然被忽略,因爲第一個參數包含一個空格:
Preparsing Command Set: [pushd cleartool desc [email protected]@$2], using Params: 'foo bar main\1'.
Command Set Parsed To: [pushd cleartool desc "[email protected]@bar"]
我試圖通過在調用命令加雙引號解決這個:
<run command="cc_describe" params=""$1" $2"/>
雙引號使其進入命令,但不要有所作爲:
Preparsing Command Set: [pushd cleartool desc [email protected]@$2], using Params: '"foo bar" \main\1'.
Command Set Parsed To: [pushd cleartool desc "[email protected]@bar"]
未遂解決方案:將@@移動到調用命令,將其從接收命令中移除並添加附加參數(以便能夠處理1個空格):
<run command="cc_describe" params="[email protected]@$2"/>
<command name="cc_describe">
<execute>
pushd cleartool desc $1$2$3;
</execute>
</command>
執行結果:
Preparsing Command Set: [pushd cleartool desc [email protected]@$2$3], using Params: 'foo bar \main\1'.
Command Set Parsed To: [pushd cleartool desc "[email protected]@\main\1"]
再次,做得好! +1 – VonC