如何从Yii网页和Python执行MonkeyRunner

时间:2015-11-11 00:18:54

标签: php android python yii2 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的一些想法。感谢。

1 个答案:

答案 0 :(得分:1)

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

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