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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵