无法使用groovy脚本执行plink命令

时间:2017-11-20 09:05:03

标签: android groovy ssh adb plink

我遇到了在windows上运行的 plink 命令的问题.Below是我要触发远程Android设备的iptable的命令。

plink.exe -v -ssh rauser @ HOSTNAME -pw PASSWORD iptables -D INPUT -p tcp -m tcp --dport 5555 -j DROP

我可以手动从命令提示符执行命令,但是当我从groovy脚本执行命令作为bat文件时,它会抛出一个错误。我正在和你共享。

Groovy脚本

// enable ADB
commandsList.add(""
    "enable-adb.bat "
    "" + deviceip)
// run adb commands
commandsList.each {
        def command = pathtoadb + it
        log.info command
        def proc = command.execute()
        proc.waitFor() // Wait for the command to finish
        // Obtain status and output
        log.info "return code: ${ proc.exitValue()}" // "0" is success
        //log.info "stderr: ${proc.err.text}"
        log.info "stdout: ${proc.in.text}" // *out* from the external program is *in* for groovy
        def error = proc.err.text;
        // if the output contains "Bad rule" that means ADB is already enabled and we don't want the test to fail
        if (!error.contains("Bad rule")) {
            log.info "  _______  There was a problem connecting to your device using SSH. Check if remote access is enabled on your device"
            log.info("ERROR:   " + error)
        } else {
            log.info "  _______  return code is 1 because ADB was already enabled - this is not a failure"
            log.info("        ********    ADB has been enabled on device -->  " + deviceip)
        }

执行消息

Server version: SSH-2.0-OpenSSH_5.9
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.62
Doing Diffie-Hellman group exchange
Server unexpectedly closed network connection
FATAL ERROR: Server unexpectedly closed network connection

0 个答案:

没有答案