Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute two shell commands in single exec php statement

Tags:

php

exec

I want to display all the files that are modified after a specified date

the commands are

touch --date '2011-09-19 /home/  , find /home/

How i can execute this two commands in single exec statement.Thanks in advance

like image 544
Warrior Avatar asked Aug 19 '11 14:08

Warrior


2 Answers

You can use either a ; or a && to separate the comands. The ; runs both commands unconditionally. If the first one fails, the second one still runs. Using && makes the second command depend on the first. If the first command fails, the second will NOT run.

command1 ; command2     (run both uncondtionally)
command1 && command2     (run command2 only if command1 succeeds)
like image 53
Marc B Avatar answered Nov 05 '22 21:11

Marc B


This is how I did it simultaneously encode thumbs, and then flv video..I need to generate 2 thumbs from avi file. After the thumbs I need to convert the same avi to flv or whatever. So, here is the code I normally used.

$command_one = "do whatever the script does best";
$command_two = "do whatever the script does second best";
//execute and redirect standard stream ..
@exec($command_one."&& ".$command_two.">/dev/null 1>/dev/null 2>/dev/null &");

You can also run array of commands with exec, if you want :)

foreach($crapatoids as $crap){

$command_name = $crap;
//exec the crap below
@exec ($command_name." >/dev/null 1>/dev/null 2>/dev/null &");
}
like image 5
PoorBoy Avatar answered Nov 05 '22 20:11

PoorBoy