27

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

Warrior
  • 5,168
  • 12
  • 60
  • 87

5 Answers5

61

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)
Petrogad
  • 4,405
  • 5
  • 38
  • 77
Marc B
  • 356,200
  • 43
  • 426
  • 500
5

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 &");
}
PoorBoy
  • 51
  • 1
2

Seperate them with a semicolon (;). Example:

exec("touch --date '2011-09-19' /home/; find /home/");
Rijk
  • 11,032
  • 3
  • 30
  • 45
  • Try the line of code I posted. It should work - provided the commands' syntax is correct. – Rijk Aug 19 '11 at 14:09
2

The semicolon separator allows you to run multiple commands on one line.

<?php
    $output = shell_exec("touch --date '2011-09-19' /home/; find /home/");
    echo "<pre>" . $output . "</pre>";
?>
JJ.
  • 5,425
  • 3
  • 26
  • 31
1

Actually, my problem came from execution python file in a virtual environment of Python. Generally, Python website instructs us to go through command lines: create a virtual env --> activate it --> call Python file (e.g: python3 yourPyFile.py). However, when I was trying to adapt these steps through calling in php with exec() method, it didn't work. Finally, I found out you don't need to activate env at all, what you only need to use a python which already generated when you creating virtual env by path/to/virtual/env/bin/python3 yourPyFile.py.

Nguyen Tan Dat
  • 3,780
  • 1
  • 23
  • 24