我需要运行一个包含’<‘的命令在里面. 我可以从命令行运行它,但是当我把它放入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: $@"
命令行输出:
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>
我试图改变’<‘到’& lt;’,将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
我怀疑’<‘参数,但我不确定什么是真正的问题. 有小费吗? 更新:当我说“我试图改变’<‘时到’& lt;’,将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%
不好,但魔术:-)