我需要运行一个包含“<”的命令。
我可以从命令行运行它,但是当我将它放入 mvn exec 时它会抛出错误。
命令:
c:\apps\putty\plink.exe myuser@myhost -T -ssh -2 $SHELL /dev/stdin 'a b c d' < test.sh
测试.sh:
#!/bin/bash
echo "execution parameters: $@"
命令行输出:
execution parameters: a b c d
pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration><executable>c:\apps\putty\plink.exe</executable>
<commandlineArgs>"myuser@myhost -T -ssh -2 $SHELL /dev/stdin 'a b c d' < test.sh"</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
我尝试将“<”更改为“<”,将 commandlineArgs 放入 CDATA,将 doubleqoutes (") 置于任何地方,但无法使其正常工作。
[DEBUG] Executing command line: [c:\apps\putty\plink.exe, > myuser@myhost -T -ssh -2 -pw tomcat $SHELL /dev/stdin 'a b c d' < test.sh]
Unable to open connection: Host does not exist[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
或者:
[DEBUG] Executing command line: [c:\apps\putty\plink.exe, myuser@myhost, -T, -ssh, -2, -pw, tomcat, $SHELL /dev /stdin 'a b c d' < test.sh]
bash: test.sh: No such file or directory [INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
我怀疑 '<' 参数,但我不确定真正的问题是什么。
有小费吗?
更新:当我说“”时,我尝试将“<”更改为“<”,将 commandlineArgs 放入 CDATA,将 doubleqoutes (") 放在任何地方,但无法使其正常工作。 “- 我是认真的!
最佳答案
如果我将它包装在 .bat 文件中,它就可以工作:
@echo off
set plinkExec=%1
set env=%2
set user=%3
set pass=%4
set shellPath=%5
...
%plinkExec% %user%@%env% -T -ssh -2 -pw %pass% $SHELL /dev/stdin '...' < %shellPath%
不太好,但有魔力:-)
关于maven - mvn exec :exec with '<' in commandlineArgs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35430716/