2016-08-31 10:17 阅读 127


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 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

    点赞 评论 复制链接分享
  • douyong5476 douyong5476 2016-08-31 10:30

    1)give the full path to php file

    2)pass the second and third parameter and know the output and return value.

    $cmd = "(touch $run_file && java -jar $trimmomatic SE -threads 8 $file $trimmed_file HEADCROP:5 && rm $run_file && php -f /var/www/cloud/confirm.php)";
    exec($cmd . " 2>&1", $output, $return_var);
    点赞 评论 复制链接分享