问题
my problem is, that the output from the ant task alwas has some [ssh-exec] infotext at the beginning. can i suppress / disable that?
my code so far:
def ant = new AntBuilder()
// .... variable definition ...
ant.sshexec(host: host,
port: port,
trust: true,
username: username,
password: password,
command: 'ls')
>>> output:
[sshexec] Connecting to foomachine.local:22
[sshexec] cmd : ls
[sshexec] oldarchive.gz
[sshexec] newarchive.gz
[sshexec] empty-db.sh
[sshexec] testfile.py
i just want to have the raw output from the cmd i execute...
some ideas?!
回答1:
You can save the raw output inside an Ant property:
def ant = new AntBuilder()
ant.sshexec(host: host,
port: port,
trust: true,
username: username,
password: password,
command: 'ls',
outputproperty: 'result')
def result = ant.project.properties.'result'
回答2:
the problem is that outputproperty is not working properly (it does not set the ant variable).
I often use trycatch from antcontrib to test if error occurs instead of reading return value.
Example :
<trycatch>
<try>
<sshexec host="@{host}" failonerror="true" username="${username}" password="${password}" timeout="${ssh.timeout}" command="@{command}" usepty="@{usepty}" trust="true" />
</try>
<catch>
<echo>Service already stopped!</echo>
</catch>
</trycatch>
回答3:
I tripped over the same issue in gradle and from there I had to change the way to access the property: According to the official gradle doc 3.3
println ant.antProp
println ant.properties.antProp
println ant.properties['antProp']
is the correct way to go.
def ant = new AntBuilder()
ant.sshexec(host: host,
port: port,
trust: true,
username: username,
password: password,
command: 'ls',
outputproperty: 'result')
def result = ant.properties.'result'
Hope this helps people in the same situation. Cheers
来源:https://stackoverflow.com/questions/7121637/getting-well-formed-output-from-ant-sshexec-in-groovy-script