I need to run a monkeyrunner script in a remote machine. I'm using python to to automate it and RPyC so that I could connect to other machines, everything is running in CentOS.
written below is the command that I used:
import rpyc
import subprocess
conn = rpyc.classic.connect("192.XXX.XXX.XXX",XXXXX)
conn.execute ("print 'Hello'")
subprocess.Popen("/opt/android-sdk/tools/monkeyrunner -v ALL
/opt/android-sdk/tools/MYSCRIPT.py", shell=True)
and this is the result:
can't open specified script file
Usage : monkeyrunner [option] script_file
-s MonkeyServer IP Address
-p MonkeyServer TCP Port
-v MonkeyServer Logging level
And then I realized that if you use the command below, it is running the command in your machine. (example: the command inside the Popen is "ls" the result that it will give you is the list of files and directories in the current directory of the LOCALHOST) hence, the command is wrong.
subprocess.Popen("/opt/android-sdk/tools/monkeyrunner -v ALL
/opt/android-sdk/tools/MYSCRIPT.py", shell=True)
and so I replaced the code with this
conn.modules.subprocess.Popen("/opt/android-sdk/tools/monkeyrunner -v ALL
/opt/android-sdk/tools/MYSCRIPT.py", shell=True)
And give me this error message
======= Remote traceback ======= Traceback (most recent call last): File
"/usr/lib/python2.4/site-packages/rpyc-3.2.2-py2.4.egg/rpyc/core/protocol.py",
line 300, in _dispatch_request
res = self._HANDLERS[handler](self, *args) File "/usr/lib/python2.4/site-packages/rpyc-3.2.2-py2.4.egg/rpyc/core/protocol.py",
line 532, in _handle_call
return self._local_objects[oid](*args, **dict(kwargs)) File "/usr/lib/python2.4/subprocess.py", line 542, in init
errread, errwrite) File "/usr/lib/python2.4/subprocess.py", line 975, in _execute_child
raise child_exception OSError: [Errno 2] No such file or directory
======= Local exception ======== Traceback (most recent call last): File "", line 1, in ? File
"/usr/lib/python2.4/site-packages/rpyc-3.2.2-py2.4.egg/rpyc/core/netref.py",
line 196, in call
return syncreq(_self, consts.HANDLE_CALL, args, kwargs) File "/usr/lib/python2.4/site-packages/rpyc-3.2.2-py2.4.egg/rpyc/core/netref.py",
line 71, in syncreq
return conn.sync_request(handler, oid, *args) File "/usr/lib/python2.4/site-packages/rpyc-3.2.2-py2.4.egg/rpyc/core/protocol.py",
line 438, in sync_request
raise obj OSError: [Errno 2] No such file or directory
I am thinking that it cannot run the file because I don't have administrator access (since I didn't supply the username and password of the remote machine)?
Help!
As i see you are already connected
conn = rpyc.classic.connect("192.XXX.XXX.XXX",XXXXX)
conn.execute ("print 'Hello'")
Try to use next command:
subprocess.Popen("/opt/android-sdk/tools/monkeyrunner
/opt/android-sdk/tools/MYSCRIPT.py", shell=True)
instead of:
subprocess.Popen("/opt/android-sdk/tools/monkeyrunner -v ALL
/opt/android-sdk/tools/MYSCRIPT.py", shell=True)
Using this function to run monekyrunner doesn't work although running ls, pwd works fine.
conn.modules.subprocess.Popen("/opt/android-sdk/tools/monkeyrunner -v
ALL
/opt/android-sdk/tools/MYSCRIPT.py", shell=True)
The chunk of code below solved my problem :
import rpyc
import subprocess , os
conn = rpyc.classic.connect("192.XXX.XXX.XXX",XXXXX)
conn.execute ("print 'Hello'")
conn.modules.os.popen("monkeyrunner -v ALL MYSCRIPT.py",)
Hope this helps to those who are experiencing the same problem as mine.
Related
I'm trying to send command through socket with subprocess (python 2.7 (qpython android)).
here 's the code :
#reponse is my command
x = subprocess.Popen(reponse,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
y = str(x.stdout.read() + x.stderr.read())
But when i'm trying, i've got this error :
Traceback (most recent call last):
File "ser.py", line 72, in <module>
stdin=subprocess.PIPE)
File "/QPython/QPython2-core/build/python-install/lib/python2.7/subprocess.py",
line 679, in __init__
File "/QPython/QPython2-core/build/python-install/lib/python2.7/subprocess.py",
line 1228, in _execute_child
OSError: [Errno 2] No such file or directory
So, can someone tell me what's wrong, and how to fixe this .. Thx in advance for help...
I found that commands don't work if you specify shell=True.
I had the same error.
You should use the commands and its arguments as a list; i.e.:
your_cmd = ['examplecmd', '-a', 'foo', '-b', 'bar']
I have generated the template using command $ culebra -U -o mytest.py and using for com.csr.csrmeshdemo:id/powerSwitch to turn on and off the switch.
It worked fine for first time but after restarting system for another issue I am unable to run my python script. getting error like this:
*root#parameshwar:~/Desktop/monkey/adt-bundle-linux-x86_64-20131030/sdk/CSR_script# adb devices
List of devices attached
T00940ZEIM device
root#parameshwar:~/Desktop/monkey/adt-bundle-linux-x86_64-20131030/sdk/CSR_script# python t6.py
E
======================================================================
ERROR: testSomething (__main__.CulebraTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "t6.py", line 44, in testSomething
self.vc.dump(window='-1')
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.6-py2.7.egg/com/dtmilano/android/viewclient.py", line 3270, in dump
self.setViewsFromUiAutomatorDump(received)
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.6-py2.7.egg/com/dtmilano/android/viewclient.py", line 2927, in setViewsFromUiAutomatorDump
self.__parseTreeFromUiAutomatorDump(received)
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.5.6-py2.7.egg/com/dtmilano/android/viewclient.py", line 3109, in __parseTreeFromUiAutomatorDump
raise ValueError("received does not contain valid XML data")
ValueError: received does not contain valid XML data
----------------------------------------------------------------------
Ran 1 test in 2.508s
FAILED (errors=1)*
Please help me with this..
Latest AndroidViewClient/culebra 11.5.7 adds more verbose information about the exception and would let you trace the root cause easily.
I'm currently trying to run the systrace python script that is included in the platform-tools folder and I'm getting the following error:
File "systrace.py", line 274, in <module>
main()
File "systrace.py", line 60, in main
device_sdk_version = get_device_sdk_version()
File "systrace.py", line 44, in get_device_sdk_version
stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I'M running on Ubuntu 12.04 LTS. Here is the command I'm using to run systrace:
sudo python systrace.py -o output.html
NOTE: The sudo is in order to avoid the following error:
File "systrace.py", line 274, in <module>
main()
File "systrace.py", line 63, in main
os.execv(legacy_script, sys.argv)
OSError: [Errno 13] Permission denied
After doing some searching around the web I found that one solution was to add the adb to my PATH variable. I added the platform-tools directory to my PATH and I'm still getting the same error. I went ahead to check the code that is causing the problem and apparently its this snippet:
adb = subprocess.Popen(getprop_args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
where getprop_args is defined as follows:
getprop_args = ['adb', 'shell', 'getprop', 'ro.build.version.sdk']
From what I understand the code is trying to run the following command:
adb shell getprop ro.build.version.sdk
I ran the command in console and it work with no problem. I also copied both lines of code and ran them in python interpreter and it ran without a problem. I really don't know how to solve this issue. Does anyone know of a possible solution?
Ok so I found out what the problem was. The problem was the sudo that I was putting right before python systrace.py -o output.html I didn't know but I guess the PATH variable is different when using sudo, than when not using it. So the PATH in sudo didn't have the platform-tools directory. So I removed the sudo and I was getting the following error:
File "systrace.py", line 274, in <module>
main()
File "systrace.py", line 63, in main
os.execv(legacy_script, sys.argv)
OSError: [Errno 13] Permission denied
To solve this problem I ran the following command on the legacy_script:
$chmod +x ./systrace-legacy.py
And now I was able to run the systrace script without a problem :P
this problem is causing by PATH. adb path should put the end of the other path.
for example:
$ sudo gedit /etc/environment;
PATH="...:~/softAddr/adt-bundle-linux-x86_64-20140624/sdk/platform-tools:~/softAddr/adt-bundle-linux-x86_64-20140624/sdk/tools"
not:
PATH="~/softAddr/adt-bundle-linux-x86_64-20140624/sdk/platform-tools:~/softAddr/adt-bundle-linux-x86_64-20140624/sdk/tools:..."
I finally managed to successfully build a Nexus 10 image (full_manta-userdebug) with Google Mobile Services installed but unfortunately, I'm unable to use my MonkeyRunner script that uses AndroidViewClient. It crashes out of the script with the following:
/system/bin/sh: uiautomator: not found
130628 14:12:41.242:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions] Script terminated due to an exception
130628 14:12:41.242:S [MainThread] [com.android.monkeyrunner.MonkeyRunnerOptions]Traceback (most recent call last):
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 361, in <module>
main()
File "/home/allen/projects/cts-scripts/4.2/cts-setup.py", line 339, in main
vc = ViewClient(device, serialno)
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1188, in __init__
self.dump()
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1780, in dump
self.setViewsFromUiAutomatorDump(received)
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1530, in setViewsFromUiAutomatorDump
self.__parseTreeFromUiAutomatorDump(received)
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 1688, in _ViewClient__parseTreeFromUiAutomatorDump
self.root = parser.Parse(receivedXml)
File "/home/allen/projects/AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py", line 988, in Parse
parserStatus = parser.Parse(uiautomatorxml, 1)
File "/home/allen/android/android-sdks/tools/lib/jython-standalone-2.5.4-rc1.jar/Lib/xml/parsers/expat.py", line 212, in Parse
xml.parsers.expat.ExpatError: Content is not allowed in prolog.
Do I need to install the ViewServer for this to work or did I forget to include the uiautomator backend when I built the image?
Try uiautomator from command line to find out if it's there or not:
$ adb shell uiautomator
if your output is similar to
Usage: uiautomator <subcommand> [options]
Available subcommands:
help: displays help message
...
then you have uiautomator installed. Otherwise if the output is
/system/bin/sh: uiautomator: not found
then you forgot to include it in the image.
You don't need ViewServer if UiAutomator is used as AndroidViewClient back-end.
I've followed the instructions Google has provided on downloading the Source Tree, but after I run the command
$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.7_r1
and I receive the following error message :
$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.7_r1
Traceback (most recent call last):
File "/Users/roboguy12/bin/repo", line 690, in <module>
main(sys.argv[1:])
File "/Users/roboguy12/bin/repo", line 657, in main_Init(args)
File "/Users/roboguy12/bin/repo", line 189, in _Init_CheckGitVersion()
File "/Users/roboguy12/bin/repo", line 214, in _CheckGitVersion
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 595, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1106, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
What did I do wrong? Or is this just an error on behalf of Repo?
UPDATE: Now that I've installed Python 2.7, I still have almost the exact same error message:
$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.7_r1
Traceback (most recent call last):
File "/Users/roboguy12/bin/repo", line 690, in <module>
main(sys.argv[1:])
File "/Users/roboguy12/bin/repo", line 657, in main_Init(args)
File "/Users/roboguy12/bin/repo", line 189, in _Init_CheckGitVersion()
File "/Users/roboguy12/bin/repo", line 214, in _CheckGitVersion
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I call $ python -V and it says Python 2.7.1, so I don't know what else I can do.
Seems to me you might have not done a couple of things: chmod'd the repo to +x and/or put it in your $PATH statement as the first directory to look for (and could be using another version of repo). Have you tried 'ls -al' instead? The directory you're looking for is hidden and you need the -a argument in ls to view hidden files/directories.
UPDATE: Ah, just saw your update. Since you're using a Mac, you need to use Python 2.7. To do so, you'll need to MacPort it. This website provided much help to me: INSTALLING PYTHON 2.7, EASY_INSTALL, PIP, VIRTUALENV AND VIRTUALENVWRAPPER ON MAC OS X