python process - ghdrako/doc_snipets GitHub Wiki

proc = Popen(["docker", "login", "--password-stdin"], stdin=PIPE)
out, err = proc.communicate(my_password + "\n")If
with tempfile.TemporaryFile() as fp:    
  fp.write(contents)    
  fp.write(of)    
  fp.write(email)    
  fp.flush()    
  fp.seek(0)    
  proc = Popen(["sendmail"], stdin=fp)    
  result = proc.poll()
In fact, in this case, you can even use the check_callfunction.
with tempfile.TemporaryFile() as fp:    
  fp.write(contents)    
  fp.write(of)    
  fp.write(email)    
  fp.flush()    
  fp.seek(0)    
  check_call(["sendmail"], stdin=fp)If


sha = subprocess.check_output(          
         ["git", "rev-parse", "HEAD"],          
          cwd="src/some-project").decode("ascii").strip()

This gets the current git hash of the project, assuming the project is a git directory. If it is not, git rev-parse HEAD returns non-zero, and causes an exception to be raised