java - Ant sshexec task called from gradle doesn't show output -


i want use apache ant sshexec task in gradle custom task. problem task doesn't work (output not shown in console , sshexec action not executed). how use it:

configurations {     sshexecanttask }  repositories {     mavencentral() }  dependencies {     sshexecanttask 'org.apache.ant:ant-jsch:1.7.0' }  // ----------------------------------------------------  import java.nio.file.filealreadyexistsexception; import java.nio.file.files  class mycustomtask extends defaulttask {      @taskaction     def build() {         string command = ""         command = 'cmd.exe /c mdir c:\\aadd'         runsshcommand(command)     }      private void runsshcommand(string command) {         string host = "host"         string username = "username"         string password = "password"          ant.taskdef(name: 'sshexec', classname: 'org.apache.tools.ant.taskdefs.optional.ssh.sshexec', classpath: project.configurations.sshexecanttask.aspath)         // command not executed; why?         ant.sshexec(host: host, username: username, password: password, command: command, trust: 'true', failonerror: 'true')     }  } 

[edit] i've tested sshexec , results:

  1. the command cmd.exe /c echo test > c:\testresult.txt started ant works correctly , output returned file.
  2. the command cmd.exe /c echo test > c:\testresult.txt started gradle works correctly , output returned file. great!
  3. the command cmd.exe /c echo test started ant works correctly , output returned stdout. !
  4. the command cmd.exe /c echo test started gradle works correctly output not returned stdout. !
  5. the command cmd.exe /c mkdir c:\\\\inetpub\\\\ftproot\\\\temp\\\\jakisnowykatalog started ant works correctly , directory created (i need use \\\\ path separator because \\, \, / doesn't work)
  6. the command cmd.exe /c mkdir c:\\\\inetpub\\\\ftproot\\\\temp\\\\jakisnowykatalog started gradle doesn't work , directory not created.

i should add want connect windows ssh server (not unix/mac) i've tested commands mac shh without success. please help!

[another edit] i've created groovy test code uses jsch library execute command , works. still don't know why ant task doesn't work.

import com.jcraft.jsch.* import java.util.properties;  private void jschtest() {     session session = null     channel channel = null     try {         jsch jsch = new jsch()         session = jsch.getsession("host", "login", 22)         session.setpassword("password")         properties config = new properties()         config.put("stricthostkeychecking", "no")         session.setconfig(config)         session.connect()          string command = "cmd.exe /c mkdir c:\\gradledir"         channel = session.openchannel("exec");         ((channelexec)channel).setcommand(command);         channel.connect()     }     catch (exception e) {         println e.getmessage()     }     {         if (session!=null) {             session.disconnect()         }         if (channel!=null) {             channel.disconnect()         }     } } 

assuming declare task of type mycustomtask , execute correctly, see no reason why ant task wouldn't executed. problem more elsewhere (e.g. wrong configuration of ant task).


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -