使用PHP的shell_exec()运行cordova -v

时间:2016-06-02 12:09:52

标签: php linux cordova ubuntu

有没有人设法成功让PHP shell_exec()成功运行Cordova-CLI命令?基本上,当我运行以下内容时:

<?php
    try {
        putenv('PATH='. getenv('PATH') .':/usr/local/bin');
        exec('cordova -v 2>&1', $output);
        print_r($output);
    }
    catch(Exception $ex) {
        echo '<pre>';
        print_r($ex);
    }
?>

我得到以下结果:

Array
(
    [0] => path.js:8
    [1] =>     throw new TypeError('Path must be a string. Received ' +
    [2] =>     ^
    [3] => 
    [4] => TypeError: Path must be a string. Received undefined
    [5] =>     at assertPath (path.js:8:11)
    [6] =>     at Object.posix.join (path.js:479:5)
    [7] =>     at Object.<anonymous> (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/util.js:35:31)
    [8] =>     at Module._compile (module.js:410:26)
    [9] =>     at Object.Module._extensions..js (module.js:417:10)
    [10] =>     at Module.load (module.js:344:32)
    [11] =>     at Function.Module._load (module.js:301:12)
    [12] =>     at Module.require (module.js:354:17)
    [13] =>     at require (internal/module.js:12:17)
    [14] =>     at Object.<anonymous> (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/cordova.js:21:20)
)

当我尝试使用php shell_exec运行Cordova时,它只显示相同的错误。为了测试我只打印出Cordova的版本。但错误仍然存​​在。当我在Ubuntu上使用终端时,Cordova运行得很好,但它不能在PHP应用程序上运行。

0 个答案:

没有答案