我已安装 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)
关于php - 如何从 Yii 网页和 Python 执行 MonkeyRunner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33642150/