douque9982
douque9982
2012-12-30 14:46

调用运行bash脚本的某些php脚本函数

已采纳

I have a php script (functions.inc):

<?php  
function exec_mount_secured_bucket(){  
exec("/ilantest/testscript.sh");  
}  
?>  

I would like to run that function from inside the shell, normally to run the script using php i would do:
php function.inc
But I want to call a certain function from that function file.

How to do it ?

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dongyoufo5672 dongyoufo5672 9年前

    You can use the command line switches for this purpose:

    --process-end code
    -E code        Run PHP code after processing all input lines
    

    This should do the job:

    php -E 'exec_mount_secured_bucket();' function.inc
    
    点赞 评论 复制链接分享
  • dousi2553 dousi2553 9年前

    Create a file like this:

    launcher.php

    <?php
        include 'functions.inc';
        exec_mount_secured_bucket();
    

    Then in your bash script:

    php launcher.php
    
    点赞 评论 复制链接分享

相关推荐