2011-08-19 33 views

回答

31

您可以使用一个;&&的命令对应的分离。 ;无条件地运行这两个命令。如果第一个失败,第二个仍然运行。使用&&使第二个命令依赖于第一个命令。如果第一个命令失败,第二个命令将不会运行。

command1 ; command2  (run both uncondtionally) 
command1 && command2  (run command2 only if command1 succeeds) 
2

用分号(;)分隔它们。例如:

exec("touch --date '2011-09-19' /home/; find /home/"); 
+1

我曾尝试它不工作 – Warrior

+0

尝试的代码我张贴的线路。它应该工作 - 只要命令的语法是正确的。 – Rijk

1

分号分隔允许你在一行运行多个命令。

<?php 
    $output = shell_exec("touch --date '2011-09-19' /home/; find /home/"); 
    echo "<pre>" . $output . "</pre>"; 
?> 
2

这就是我这样做的同时编码拇指,然后FLV视频..我需要从AVI文件生成2拇指。拇指后,我需要将相同的AVI转换为FLV或其他。所以,这里是我通常使用的代码。

$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 &"); 

您还可以使用EXEC命令运行的阵列,如果你想:)

foreach($crapatoids as $crap){ 

$command_name = $crap; 
//exec the crap below 
@exec ($command_name." >/dev/null 1>/dev/null 2>/dev/null &"); 
}