duannian7116
2014-04-29 05:14
浏览 69

如何使用php运行phonegap?

how to run phonegap cli using php scripts?
i can manually run phonegap with windows cmd and everything works great but when i call ex:'phonegap build android' in php exec, nothing happens. no error no catch block, nothing.

here is my code:

test.php

<?php
$out = array();
try {
    $create_command = 'phonegap create test';
    $build_command = 'phonegap build android';
    exec($build_command,$out);
    foreach($out as $line) echo $line.'<br>';
}
catch(Exception $ex) {
    echo $ex->getMessage();
}
?>

by the way i registered php in environments then ran 'php %path_to_file%/test.php' in cmd and it worked.

图片转代码服务由CSDN问答提供 功能建议

如何使用php脚本运行phonegap cli?
i可以手动运行带有windows cmd的phonegap,一切正常 很棒但是当我在php exec中调用ex:'phonegap build android'时,没有任何反应。 没有错误没有catch块,什么都没有。

\我的代码是什么:

test.php

 &lt;?php 
 $ out = array(); 
try {
 $ create_command ='phonegap create test'; 
 $ build_command ='phonegap build android'; \  n exec($ build_command,$ out); 
 foreach($ out as $ line)echo $ line。'&lt; br&gt;'; 
} 
catch(Exception $ ex){
 echo $ ex-&gt;  getMessage(); 
} 
?&gt; 
   
 
 

通过我在环境中注册php然后运行'php%path_to_file%/ test.php'的方式 cmd,它工作。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongpaipu8394 2014-05-11 04:44
    已采纳

    thanks for your replies. but there was nothing wrong with my codes. problem was fast-cgi which is not installed by default on xampp. i changed my web server to nginx using this web server WT-NMP.

    点赞 打赏 评论
  • douzhi6160 2014-05-08 07:32

    Change this:

    exec($build_command,$out);<br>
    foreach($out as $line) echo $line.'<br>';
    

    by this:

    passthru( $build_command );
    

    The passthru command does the same as exec and writes the resulting code directly to the browser.

    点赞 打赏 评论
  • dpql57753 2014-05-08 11:36

    Try below:

    <?php
    function sys_cmd($cmd)
    {   
        $hd = popen($cmd,"r") or die('function disabled');
        while (!feof($hd))
        {
            $rs .= fread($hd,1024);     
        }
        pclose($hd);
        return $rs;
    }
    
    out = array();
    try {
        $create_command = 'phonegap create test';
        $build_command = 'phonegap build android';
    
        sys_cmd ($build_command, $out);
    
        foreach($out as $line){
            echo $line.'<br>';
        }
    }
    
    catch(Exception $ex) {
        echo $ex->getMessage();
    }
    ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题