我需要运行一个包含'<'字符的命令。
我可以在命令行中运行它,但是当我将其放到mvn exec中时,会出现错误。
该命令:
c:\apps\putty\plink.exe myuser@myhost -T -ssh -2 $SHELL /dev/stdin 'a b c d' < test.sh
test.sh:
#!/bin/bash
echo "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中,到处使用双引号("),但无法使其正常工作。
[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中,到处放置双引号(“),但无法使其正常工作时”,我的意思是!
<commandlineArgs>"myuser@myhost -T -ssh -2 $SHELL /dev/stdin 'a b c d' < test.sh"</commandlineArgs>
中,Maven不知何故得出myhost -T -ssh -2 $SHELL /dev/stdin 'a b c d' < test.sh
是主机。 - Haris Osmanagić