在groovy脚本中从ant-sshexec获得格式良好的输出
我的问题是,ant任务alwas的输出在开始时有一些[ssh exec]信息文本。我可以抑制/禁用它吗 到目前为止,我的代码是:在groovy脚本中从ant-sshexec获得格式良好的输出,ant,groovy,ssh,Ant,Groovy,Ssh,我的问题是,ant任务alwas的输出在开始时有一些[ssh exec]信息文本。我可以抑制/禁用它吗 到目前为止,我的代码是: def ant = new AntBuilder() // .... variable definition ... ant.sshexec(host: host, port: port, trust: true, username: username, passwor
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
我只想让我执行的命令的原始输出
一些想法 您可以将原始输出保存在Ant属性中:
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'
问题是outputproperty工作不正常(它没有设置ant变量) 我经常使用antcontrib的trycatch来测试是否发生错误,而不是读取返回值 例如:
<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>
服务已经停止!
我在gradle遇到了同样的问题,因此我不得不改变访问酒店的方式:
据
这是正确的方法
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'
希望这能帮助处于同样情况的人。干杯如果这正是你想要的,我建议你接受答案!:)不知道为什么,但我的outputproperty保持为空。
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'