I got stuck in a issue with plink command running on windows.Below is the command I am firing to drop iptable of remote android device.
plink.exe -v -ssh rauser#HOSTNAME -pw PASSWORD iptables -D INPUT -p tcp -m tcp --dport 5555 -j DROP
I am able to execute the command from command prompt manually but when I am executing command as a bat file from groovy script it throws me an error.I am sharing both with you.
Groovy Script
// 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)
}
Exeception Message
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
Related
When using 'adb pull ...' the output is sent to stderr regardless of success. Is there any reason for this? For an example, pulling a file that is there and pulling a file that doesn't exist:
When I run:
adb pull /data/data/good_file.txt /tmp`
I get the following:
stdout:
stderr: 0 KB/s (13 bytes in 0.078s)
(i.e. no stdout)
Then when when I run:
adb pull /data/data/bad_file.txt /tmp
I get the following:
stdout:
stderr: remote object '/data/bad_file.txt' does not exist
The program below was used to generate the above results:
from subprocess import Popen
cmd = "adb pull /data/data/good_file.txt /tmp"
p = Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print cmd
print "stdout: " + out
print "stderr: " + err
I have the same issue with: adb install -r /foo/bar.apk and sound like adb always send his result to stderr, just add 2>&1 at end and it solves the problem.
cmd = "adb pull /data/data/good_file.txt /tmp 2>&1"
The 2>&1 just redirects Channel 2 (Standard Error) and Channel 1
(Standard Output) to the same place which in this context is Channel 1
(Standard Output), and thence your log file.
I'm trying to automate the full CTS setup and execution with python & monkeyrunner on Ubuntu and most of it has gone very well. As the very final step, I try executing the following python command to start the CTS on a specific device:
cts_tradefed_script = "./android-cts/tools/cts-tradefed"
process = subprocess.Popen([cts_tradefed_script, "run", "cts", "-s", '"' + serialno + '"', "--plan", "CTS"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
which is the equivalent of:
./android-cts/tools/cts-tradefed run cts -s "R32CB054TSZ" --plan CTS
in the command-line and I get:
Android CTS 4.2_r4
No commands for non-interactive mode; exiting.
06-17 17:32:32 I/: Detected new device R32CB054TSZ
Saved log to /tmp/tradefed_global_log_9173619073367947049.txt
06-17 17:32:32 I/CommandScheduler: All done
The CTS tests don't execute. Is there a command I'm forgetting or is this not possible using Python?
cts_tradefed_script = "./android-cts/tools/cts-tradefed"
process = subprocess.Popen([cts_tradefed_script + " " + serialno], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Edit: script was not necessary. Just enter everything as a concatenated String.
The problem with non-interactive is that you cannot run more than a command, so you should try to run in interactive mode.
To run in interactive mode this is one way:
#pip install paramiko
import paramiko
import time
def run_remote_command(channel, command):
channel.send(command)
whole_output = ""
while True:
if channel.recv_ready():
output = channel.recv(1024)
whole_output+=output
else:
time.sleep(0.5)
if not(channel.recv_ready()):
return whole_output
server ="fill you own here"
username = "fill you own here"
password = "fill you own here"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server, 22 ,username, password)
channel =ssh.get_transport().open_session()
channel.get_pty()
channel.invoke_shell()
run_1 =run_remote_command(channel,"~/android/out/host/linux-x86/cts/android-cts/tools/cts-tradefed list devices" + "\n")
print run_1
run_2 =run_remote_command(channel,"run cts" + "\n")
print run_2
run_3 =run_remote_command(channel,"l i" + "\n")
print run_3
We have an android device and as part of testing I need to excute a console test application on the target device. If the test application detects an error it returns -1.
I can use adb shell to run the test applications remotely on the target but I can't find a way of getting back the return code. I need this so I that I can build this into an automated test suite.
I could try grepping the console output for some failure text but that is a bit grubby. Does anyone know of a more elegant solution?
This is a workaround to get the exit code:
adb shell '{your command here} > /dev/null 2>&1; echo $?'
This is a wrapper around adb in Ruby:
def adb(opt)
input = "#{adb_command} #{opt[:command]} #{opt[:params]}"
puts "Executing #{input}...\n"
output = nil
exit_code = 0
def wait_for(secs)
if secs
begin
Timeout::timeout(secs) { yield }
rescue
print 'execution expired'
end
else
yield
end
end
wait_for(opt[:timeout]) do
case opt[:command]
when :install, :push, :uninstall
output, exit_code = `#{input}`, $?.to_i
when :shell
input = "#{adb_command} shell \"#{opt[:params]}; echo \\$?\""
output = `#{input}`.split("\n")
exit_code = output.pop.to_i
output = output.join("\n")
else
raise 'Error: param command to adb not defined!'
end
end
return if opt[:ignore_fail] and output =~ /#{opt[:ignore_fail]}/
raise output unless exit_code == 0
end
You could use Facebook's fb-adb, a "A better shell for Android devices" which "propagates program exit status instead of always exiting with status 0".
I am trying to get the output of a WLAN driver control interface via adb shell on a motorola droid 2. The command is called wlan_cu. To run the command,I am using:
% wlan_cu -itiwlan0 -s /data/jay/stat.sh
Connection established with supplicant .../Connection> Bssid_list,
Connect, Disassociate, Status, Full_bssid_list, wPs/
Status : DISCONNECT MAC : f8.7b.7a.7b.b7.9b SSID : <empty>
BSSID : 00.00.00.00.00.00
Channel : <empty>
Driver/, Connection/, Management/, Show/, Privacy/, scAn/, roaminG/, qOs/, poWer/, eVents/, Bt coexsistance/, Report/, dEbug/, biT/, aboUt, Quit
[1] Segmentation fault wlan_cu -itiwlan0 -s /data/jay/stat.sh
The -s option is to read wlan_cu commands from a script.
% cat /data/jay/stat.sh
c s
/
q
If I try to redirect the output i.e.
% wlan_cu -itiwlan0 -s /data/jay/stat.sh &> out.txt
out.txt is created, but empty and the output still goes to screen. Anyone have an idea? been stuck on this for quite a while.
you can try to redirect both stdout and stderr to the out.txt. Try this,
# wlan_cu -itiwlan0 -s /data/jay/stat.sh > out.txt 2>&1
I'm using http://www.sparkfun.com/products/9427 as GSM module. I've built for FTDI and generic usb-serial driver. Everytime I try to pppd call GPRS I'll get pppd: connect script failed.
The commands executed were:
1. pppd /dev/ttyUSB0
2. netcfg ppp0 up
3. pppd call gprs
gprs script:
/dev/ttyUSB0
460800
crtscts
modem
noauth
debug
nodetach
usepeerdns
noipdefault
defaultroute
user ""
0.0.0.0:0.0.0.0
connect '/system/bin/chat -s -v -f /system/etc/ppp/gprs-connect-chat' `
gprs-connect-chat script:
TIMEOUT 15
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
TIMEOUT 40
'' \rAT
OK ATZ
OK "ATQ0 V1 E0 S0=0 &C1 &D2 +FCLASS=0"
OK AT+CGDCONT=1,"IP","Singtel"
OK ATDT*99#
CONNECT