2

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!

srh snl
  • 797
  • 1
  • 19
  • 42

2 Answers2

0

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)
Laser
  • 6,652
  • 8
  • 54
  • 85
  • it's still not working, the result is the same with the first set of commands that I tried. – srh snl Sep 25 '12 at 07:30
  • Do you really have this script file on remote machine? – Laser Sep 25 '12 at 07:31
  • yes. I manually checked it several times. I used find and locate command to know if it is capable of locating the file in a remote machine however those commands are giving me error msgs as well.. – srh snl Sep 25 '12 at 07:58
0

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.

srh snl
  • 797
  • 1
  • 19
  • 42