Search code examples
phpandroidpythonyii2monkeyrunner

How to execute MonkeyRunner from Yii webpage and Python


I have Installed LAMP, Yii Framework 2, Android SDK path are defined. and the code of CallTest.php (using Yii) that call a Python Script is like this:

$EmuListOnline = Yii::app()->params['pathfilesscript']."ListAVDs-Online.txt";
$UserList = Yii::app()->params['pathfilesscript'].'UserListAVDs.txt';
$ScriptStartTest = Yii::app()->params['pathfilesscript'].'TestAVDs.py';
$DebugLog = Yii::app()->params['pathfilesscript'].'debug.log';

$cmd = 'python '.$ScriptStartTest.' '.$EmuListOnline.' '.$UserList.' > '.$DebugLog.' 2>&1';
$output1 = shell_exec($cmd);
if ($output1) {
    echo "Starting<br>";
    echo $output1;
} else {
echo "Not Executed";
var_dump($output1); }

The PythonScript call MonkeyRunner, adb, and others android commands. When I execute TestAVDs.py from command Line it works, But If I Call it from Yii it return as NULL and in log shows this error:

/bin/sh: 1: monkeyrunner: not found

Code of TestAVDs.py below. I change shell_exec by exec; write the path on code but doesn't work.

for index, line in enumerate(listdevtotest):
  emulatorid = listdevtotest[index][0]
  deviceid = listdevtotest[index][1]
  subprocess.call('monkeyrunner -v ALL Test1.py ' + emulatorid + ' ' + deviceid + ' ' + str(index), shell=True)

Some ideas to execute my TestAVDs.py from Yii webpage. Thanks.


Solution

  • Use the absolute path of monkeyrunner or set the PATH environment variable before invoking the script. For example:

    subprocess.call('/path/to/monkeyrunner -v ALL Test1.py ' + emulatorid + ' ' + deviceid + ' ' + str(index), shell=True)