1

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.

4
  • 2
    Try to use code that, at least in theory, could do something. Please see: How to create a Minimal, Reproducible Example. Commented Feb 19, 2024 at 9:05
  • 1
    Where did you learn that you can execute multiple commands like this? Commented Feb 19, 2024 at 9:21
  • Does this answer your question? Multiple commands on a single line in a Windows batch file Commented Feb 19, 2024 at 9:22
  • 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. 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. Commented Feb 19, 2024 at 9:50

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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………..
-1

Earlier, only first audio file or first and last audio files 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.