如何从 Yii 网页执行 MonkeyRunner 和 Python

How to execute MonkeyRunner from Yii webpage and Python

我已经安装了LAMP、Yii Framework 2、Android SDK 路径已定义。 CallTest.php(使用 Yii)调用 Python 脚本的代码如下所示:

$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); }

Python脚本调用 MonkeyRunner、adb 和其他 android 命令。当我从命令行执行 TestAVDs.py 时它工作,但是如果我从 Yii 调用它它 return 为 NULL 并且在日志中显示此错误:

/bin/sh: 1: monkeyrunner: not found

下面 TestAVDs.py 的代码。我通过 exec 更改 shell_exec;在代码上写路径但不起作用。

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)

从 Yii 网页执行我的 TestAVDs.py 的一些想法。谢谢

调用脚本前使用monkeyrunner的绝对路径或设置PATH环境变量。例如:

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