dounieqi6959 2016-08-31 10:17
浏览 137
已采纳

从bash脚本执行php文件

My below code works fine to execute a bash script in the background from PHP:

$cmd = "(touch $run_file && java -jar $trimmomatic SE -threads 8 $file $trimmed_file HEADCROP:5 && rm $run_file)";
exec($cmd . " > /dev/null &");

What I want to add is to execute an external php file upon the completion of this command.

I tried this it but didn't work:

$cmd = "(touch $run_file && java -jar $trimmomatic SE -threads 8 $file $trimmed_file HEADCROP:5 && rm $run_file && php -f confirm.php)";
exec($cmd . " > /dev/null &");

How can I make sure to execute confirm.php upon completion of the bash script?

  • 写回答

2条回答 默认 最新

  • doushishi6513 2016-09-01 15:14
    关注

    Finally I fixed my problem. I am posting here the solution if anybody else gets stuck at the same point as I did and desperately reach here.

    In my confirm.php file, I included another file which contained functions as well as a Class object. The command line cannot execute methods in the Class object unless it is called from the original file with echo or explicitly passing the class to the command like php -r 'include "Class_file.php"; echo MyClass::method(); '. Since my confirm.php file depended on this Class for further processing, it failed here. This post helped me to figure it out:

    How do you execute a method in a class from the command line

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 手机淘宝抓清除消息接口
  • ¥15 C#无selenium
  • ¥15 LD衰减计算的结果过大
  • ¥15 用机器学习方法帮助保险公司预测哪些是欺诈行为
  • ¥15 计算300m以内的LD衰减
  • ¥15 数据爬取,python
  • ¥15 怎么看 cst中一个面的功率分布图,请说明详细步骤。类似下图
  • ¥15 为什么我的pycharm无法用pyqt6的QtWebEngine
  • ¥15 FOR循环语句显示查询超过300S错误怎么办
  • ¥15 数电设计题 没有设计思路 不知道用什么芯片进行设计 求提供设计思路