title: paramiko : how to halt script if exit code of command is not successful?
body: <p>I have this script made in python with paramiko</p>
  <pre><code># -*- coding:Utf8 -*-
  import sys
  import paramiko 
  from scp import SCPClient
  
  #Connect function
  def createSSHClient(server=&quot;ec2-35-180-205-148.eu-west-3.compute.amazonaws.com&quot;, port=22, user=&quot;admin&quot;, key=&quot;/home/user/Téléchargements/aws_webforce.pem&quot;,password=&quot;&quot;):
      &quot;createSSHClient return SSHClient object from paramiko.client class and connect to server on port using user and key&quot;   
      ssh = paramiko.client.SSHClient()
      ssh.load_host_keys(key)
      #ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #to avoid raise SSHException Server XY not found in known_hosts
      ssh.connect(hostname=server,port=port,username=user,key_filename=key)
      return ssh
  
  #Connecting
  ssh=createSSHClient()
  
  # Define progress callback that prints the current percentage completed for the file
  def progress(filename, size, sent):
      sys.stdout.write(&quot;%s's progress: %.2f%%   \r&quot; % (filename, float(sent)/float(size)*100) )
  
  # SCPCLient takes a paramiko transport and progress callback as its arguments.
  scp = SCPClient(ssh.get_transport(),progress=progress)
  
  #use scp with python: Uploading the 'corrige_exercice1_docker_compose' directory with its content in the
  # /tmp remote directory
  scp.put('corrige_exercice1_docker_compose', recursive=True, remote_path='/tmp')
  scp.close()
  
  
  for cmd in [&quot;sudo apt update&quot;,
              &quot;sudo apt install docker.io&quot;,
              &quot;sudo apt install docker-compose&quot;,
              &quot;cd /tmp/corrige_exercice1_docker_compose &amp;&amp; sudo docker-compose up -d&quot;,
              &quot;echo 'done'&quot;]:
      stdin, stdout, stderr = ssh.exec_command(cmd)
      stdout_list=stdout.readlines()
      for txt in stdout_list:    
          print(txt)
  
  ssh.close()
  </code></pre>
  <p>I first didnt do cd /tmp &amp;&amp; and ran cd /tmp in a separate command. The docker-compose didnt run correctly (i didnt have it running on the server).</p>
  <p>However, my paramiko script didnt halt or showed an error for this command.</p>
  <p>How can i set paramiko to halt on exit code of command not 0 ?</p>
  <p>I have tried to check the doc @ <a href="https://docs.paramiko.org/en/stable/api/client.html" rel="nofollow noreferrer">https://docs.paramiko.org/en/stable/api/client.html</a> but didnt find.</p>
  <p>thank you</p>