yifeng
V2EX  ›  PHP

求大神!!! php 调用 python 脚本不执行,是啥情况???

  •  
  •   yifeng · Jun 25, 2015 · 6976 views
    This topic created in 3986 days ago, the information mentioned may be changed or developed.
    php:
    <?php
    $cmd = system("/usr/bin/python test.py",$ret);
    print_r($cmd);
    echo "ret is".$ret;
    ?>

    python:
    #!/usr/bin/python
    import os
    result = os.system('reboot');

    ----------------------------------------------------------------------
    直接用python test.py可以实现机器重启,但是在php页面调用不可以,而且$ret的返回值是0

    从网上搜了很多解决方案,大都跟权限有关,都试过了还是不行,求大神怎办!!!
    6 replies    2015-06-26 04:28:02 +08:00
    cylin
        1
    cylin  
       Jun 25, 2015   ❤️ 1
    test.py和php脚本不在同一目录下吧,加上py脚本的完整路径,或者先设置正确的工作目录
    https://secure.php.net/manual/zh/function.getcwd.php
    https://secure.php.net/manual/zh/function.chdir.php
    另外。。既然python中只是执行reboot,为什么不直接用php调用呢
    yangtukun1412
        2
    yangtukun1412  
       Jun 25, 2015
    权限问题吧...
    yifeng
        3
    yifeng  
    OP
       Jun 25, 2015
    @cylin 谢谢回复,不好意思,python里是我临时添加的,因为涉及到公司业务,这里不方面贴代码
    vibbow
        4
    vibbow  
       Jun 26, 2015
    干嘛不直接用PHP重启....
    就算PHP权限不够的话,也可以在PHP里直接ssh连接到自身,然后重启啊......
    ryd994
        5
    ryd994  
       Jun 26, 2015 via Android
    testpy加hashbang加x权限直接调用试试
    q84629462
        6
    q84629462  
       Jun 26, 2015 via Android
    php.ini有没有禁用system?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2867 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 05:19 · PVG 13:19 · LAX 22:19 · JFK 01:19
    ♥ Do have faith in what you're doing.