ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DO NOT REPLY [Bug 46340] New: sshexec doesn't set outputproperty if the executed command fails (its return code is not 0)
Date Thu, 04 Dec 2008 16:14:12 GMT

           Summary: sshexec doesn't set outputproperty if the executed
                    command fails (its return code is not 0)
           Product: Ant
           Version: 1.7.1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: Optional Tasks

Created an attachment (id=22992)
 --> (
Script with dependencies that reproduces the error

I'm using <trycatch> task from ant-contrib-1.0b3 library to handle the command
failure in my script:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="ssh" basedir="." default="ssh">
        <taskdef resource="net/sf/antcontrib/antlib.xml" />

        <target name="ssh">
                                <sshexec host="nevada"
                                        command="mkdir /home" 
                                        outputproperty="tmp.output" />
                                <echo>tmp.output: ${tmp.output}</echo>

With Ant 1.7.1 I get this output:
[echo] tmp.output: ${tmp.output}

But Ant 1.7.0 gives what I'm expecting:
[echo] tmp.output: mkdir: cannot create directory `/home': File exists

Source code examination
SSHExec from Ant 1.7.1 uses this code to set outputproperty:

String output = "";
while ((cmd = br.readLine()) != null) {
    log("cmd : " + cmd, Project.MSG_INFO);
    ByteArrayOutputStream out = executeCommand(session, cmd);
    output += cmd + " : " + out + "\n";
if (outputProperty != null) {
    //#bugzilla 43437
    getProject().setNewProperty(outputProperty, output);

The problem is that when command return code is not 0 executeCommand throws
BuildException and hence outputproperty is not sent because BuildException is
thrown BEFORE it.

In Ant 1.7.0 BuildException (because of non 0 return code) is thrown AFTER
setting of outputproperty:

ByteArrayOutputStream out = new ByteArrayOutputStream();

if (outputProperty != null) {
    getProject().setProperty(outputProperty, out.toString());
if (outputFile != null) {
    writeToFile(out.toString(), append, outputFile);

// this is the wrong test if the remote OS is OpenVMS,
// but there doesn't seem to be a way to detect it.
int ec = channel.getExitStatus();
if (ec != 0) {
    String msg = "Remote command failed with exit status " + ec;
    if (getFailonerror()) {
        throw new BuildException(msg);
    } else {
        log(msg, Project.MSG_ERR);

Configure bugmail:
------- You are receiving this mail because: -------
You are the assignee for the bug.

View raw message