2011-08-19 30 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 &"); 
}