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
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………..
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:
And you can use the output varible for your purpose. However, calling exec() multiple times will be better for handling multiple data.