ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
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
https://issues.apache.org/bugzilla/show_bug.cgi?id=46340

           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
        AssignedTo: notifications@ant.apache.org
        ReportedBy: wheleph@gmail.com


Created an attachment (id=22992)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?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">
                <trycatch>
                        <try>
                                <sshexec host="nevada"
                                        username="resin"
                                        password="resin"
                                        command="mkdir /home" 
                                        trust="true" 
                                        outputproperty="tmp.output" />
                        </try>
                        <catch>
                                <echo>tmp.output: ${tmp.output}</echo>
                        </catch>
                </trycatch>
        </target>
</project>

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: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Mime
View raw message