skip to Main Content

I want to execute multiple commands in a sequence using exec() function of php (OS – windows 7, XAMPP)

For example

<?php
      exec('command1; command2; command3; command4', $output, $return_var);
?>

but only two (first and last) commands execute. What can be the issue?

UPDATED

I want to play 5 audio files in a sequence as server-side playback (using speakers of server instead of client’s speakers). I found that solution by using Copilot of Microsoft as well as in different postss of stackoverflow.com e.g. How to execute multiple commands in PHP exec
i.e. shell_exec("1.mp3 && 2.mp3 && 3.mp3 && 4.mp3 && 5.mp3"); or exec("1.mp3 && 2.mp3 && 3.mp3 && 4.mp3 && 5.mp3"); but only two (first and last) commands execute and sometimes only one / last command executes.

2

Answers


  1. Chosen as BEST ANSWER

    Earlier, only first or “first and last audio” were playing but after configuring VLC Media Player as follow now all audio files are playing "Tools" >> "Preferences." >> "All" under "Show Settings" >> "Playlist" >> "Play and Exit" And PHP code is…… exec("1.mp3 && 2.mp3 && 3.mp3 && 4.mp3 && 5.mp3");

    Anyway, thanks to all of you………..


  2. You have not provided a minimal, reproducible example so it is very tough to analyse your issue. As I can see from the info you provided, in order to run multiple commands only exec() function is eligible for this not shell_exec(). Also you need to provide the path for each value. In case of xampp it is “php” by default. Like:

    <?php
    $cmd = "php 1.mp3 && php 2.mp3 && php 3.mp3 && php 4.mp3 && php 5.mp3";
    exec($cmd, $output, $returnStatus); 
    

    And you can use the output varible for your purpose. However, calling exec() multiple times will be better for handling multiple data.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search