如何从Yii网页和Python执行MonkeyRunner



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

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

PythonScript调用MonkeyRunner、adb和其他android命令。当我从命令行执行TestAVDs.py时,它是有效的,但如果我从Yii调用它,它会返回为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)

最新更新