Bug 39186 - SSHExec task: output disappears
Summary: SSHExec task: output disappears
Status: RESOLVED DUPLICATE of bug 36302
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.6.5
Hardware: Other other
: P2 normal (vote)
Target Milestone: 1.7.0
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-03 12:06 UTC by Markus Barchfeld
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Barchfeld 2006-04-03 12:06:38 UTC
The output of a remotely executed command does not appear reliably. It seems as 
if only the first usage of sshexec within a built logs the output of the remote 
command.

The following build file part reveals the error:

	<target name="copyScript">
		<property name="local.test.script" value="C:\Temp\test.sh"/>
		<echo file="${local.test.script}">
echo "Output to stdout" 
echo "Output to stderr" 2>&amp;1			
		</echo>
		<scp file="${local.test.script}" 
remoteTofile="user@${remote.host}:${remote.test.script}"  trust="true" 
keyfile="${user.home}/.ssh/id_dsa" passphrase=""/>
	</target>

	<target name="sshExecOrgStdoutStderr" depends="copyScript">
		<sshexec host="host" username="user" command="sh 
${remote.test.script}"  trust="true" keyfile="${user.home}/.ssh/id_dsa" 
passphrase="" outputProperty="ssh.out"/>		
		<echo message="Stdout/stderr: ${ssh.out}"/>
		<sshexec host="host" username="user" command="sh 
${remote.test.script}"  trust="true" keyfile="${user.home}/.ssh/id_dsa" 
passphrase="" outputProperty="ssh.out"/>		
		<echo message="Stdout/stderr: ${ssh.out}"/>		
	</target>

The output of this build target is:

sshExecOrgStdoutStderr:
  [sshexec] Connecting to host:22
  [sshexec] Output to stdout
  [sshexec] Output to stderr
     [echo] Stdout/stderr: Output to stdout
     [echo] Output to stderr
  [sshexec] Connecting to host:22
     [echo] Stdout/stderr: Output to stdout
     [echo] Output to stderr

The lines   
[sshexec] Output to stdout
[sshexec] Output to stderr
should also appear for the second call to sshexec. The outputProperty is not 
affected.

Here is a patch which uses the LogOutputStream in order to solve the issue.

--- SSHExecMod.java	31 Mar 2006 07:25:55 -0000	1.2
+++ SSHExecMod.java	3 Apr 2006 10:54:50 -0000
@@ -25,10 +25,13 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
 import java.io.StringReader;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.LogOutputStream;
 import org.apache.tools.ant.taskdefs.optional.ssh.SSHBase;
 import org.apache.tools.ant.util.TeeOutputStream;
 
@@ -166,7 +169,7 @@
         }
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        TeeOutputStream tee = new TeeOutputStream(out, System.out);
+        TeeOutputStream tee = new TeeOutputStream(out, new LogOutputStream
(this, Project.MSG_INFO));
 
         InputStream istream = null ;
         if (this.inputFile != null) {
@@ -192,7 +195,7 @@
             final ChannelExec channel = (ChannelExec) session.openChannel
("exec");
             channel.setCommand(command);
             channel.setOutputStream(tee);
-            channel.setExtOutputStream(tee);
+            channel.setExtOutputStream(new TeeOutputStream(out, new 
LogOutputStream(this, Project.MSG_ERR)));
             channel.setInputStream(istream) ;
             channel.connect();
Comment 1 Stefan Bodewig 2006-04-12 20:24:00 UTC

*** This bug has been marked as a duplicate of 36302 ***