Ici, il faut arrêter le calcul dès qu'une commande échoue (and) ou réussit (or). On utilise une exception (on pourrait aussi écrire la fonction command_and directement sans utiliser fold_left).
      
exception Retcode of int
let rec command_and cmd_arg_list =
  try
    List.fold_left
      (fun acc (cmdargs) ->
        if acc <> 0 then raise (Retcode accelse command_wait cmd args)
      0 cmd_arg_list
  with Retcode c -> c;;

let command_or cmd_arg_list =
  try
    List.fold_left
      (fun acc (cmdargs) ->
        if acc = 0 then raise (Retcode 0) else command_wait cmd args)
      1 cmd_arg_list
  with Retcode n -> 0;;
(Remarquer que command_and [] retourne 0 (toutes les commandes ont réussi) alors que command_or [] retourne 1 (auncune commande n'a réussi).