DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=39197>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39197 Summary: SSHExec task: input property Product: Ant Version: 1.6.5 Platform: Other OS/Version: other Status: NEW Severity: enhancement Priority: P2 Component: Optional Tasks AssignedTo: dev@ant.apache.org ReportedBy: [EMAIL PROTECTED] The sshexec task should support an input property in the same was as the output property. While the output/outputProperty property stores the output (stdout and stderr) of the remote command in either a file or a property, the input/inputProperty should allow to supply stdin for the remote command. The following patch provides an implementation for input/inputProperty: Index: SSHExecMod.java =================================================================== RCS file: /usr/local/cvsveritas/build.maven.dev.tools/src/build/maven/dev/tools/sshmod/SSHExecMod.java,v retrieving revision 1.1 diff -u -r1.1 SSHExecMod.java --- SSHExecMod.java 30 Mar 2006 10:47:44 -0000 1.1 +++ SSHExecMod.java 3 Apr 2006 11:13:24 -0000 @@ -17,10 +17,14 @@ package build.maven.dev.tools.sshmod; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; import java.io.StringReader; import org.apache.tools.ant.BuildException; @@ -53,6 +57,8 @@ private String outputProperty = null; // like <exec> private File outputFile = null; // like <exec> + private String inputProperty = null; // like <exec> + private File inputFile = null; // like <exec> private boolean append = false; // like <exec> private static final String TIMEOUT_MESSAGE = @@ -93,6 +99,24 @@ public void setOutput(File output) { outputFile = output; } + + /** + * If used, the content of the file is piped to the remote command + * + * @param input The file which provides the input data for the remote command + */ + public void setInput(File input) { + inputFile = input; + } + + /** + * If used, the content of the property is piped to the remote command + * + * @param inputProperty The property which contains the input data for the remote command. + */ + public void setInputProperty(String inputProperty) { + this.inputProperty = inputProperty; + } /** * Determines if the output is appended to the file given in @@ -134,10 +158,32 @@ if (command == null) { throw new BuildException("Command is required."); } + if (this.inputFile != null && this.inputProperty != null) { + throw new BuildException("You can't specify both inputFile and inputProperty."); + } + if (this.inputFile != null && !inputFile.exists()) { + throw new BuildException("The input file " + this.inputFile.getAbsolutePath() + " does not exist."); + } ByteArrayOutputStream out = new ByteArrayOutputStream(); TeeOutputStream tee = new TeeOutputStream(out, System.out); + InputStream istream = null ; + if (this.inputFile != null) { + try { + istream = new FileInputStream(this.inputFile) ; + } catch ( FileNotFoundException e ) { + // because we checked the existence before, this one shouldn't happen + // What if the file exists, but there are no read permissions? + } + } + if (this.inputProperty != null) { + String inputData = getProject().getProperty(this.inputProperty) ; + if (inputData != null) { + istream = new ByteArrayInputStream(inputData.getBytes()) ; + } + } + Session session = null; try { // execute the command @@ -147,6 +193,7 @@ channel.setCommand(command); channel.setOutputStream(tee); channel.setExtOutputStream(tee); + channel.setInputStream(istream) ; channel.connect(); // wait for it to finish -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]