def _run_shell_command(cmd, tmpdir):
 cmdsuf = ''
 if (platform.system() == 'Windows'):
  cmdsuf = '.bat'
  cmd = ('@echo off\r\n' + cmd)
 (handle, path) = tempfile.mkstemp(text=True, dir=tmpdir, suffix=cmdsuf)
 os.write(handle, cmd.encode('utf-8'))
 os.close(handle)
 os.chmod(path, stat.S_IRWXU)
 proc = Popen(path, shell=True, stdout=PIPE, stderr=PIPE)
 proc.wait()
 (stdout, _) = proc.communicate()
 os.unlink(path)
 return _chomp(as_unicode(stdout))

def _run_shell_command ( cmd , tmpdir ) : cmdsuf = '' if ( platform . system ( ) == 'Windows' ) : cmdsuf = '.bat' cmd = ( '@echo off\r\n' + cmd ) ( handle , path ) = tempfile . mkstemp ( text = True , dir = tmpdir , suffix = cmdsuf ) os . write ( handle , cmd . encode ( 'utf-8' ) ) os . close ( handle ) os . chmod ( path , stat . S_IRWXU ) proc = Popen ( path , shell = True , stdout = PIPE , stderr = PIPE ) proc . wait ( ) ( stdout , _ ) = proc . communicate ( ) os . unlink ( path ) return _chomp ( as_unicode ( stdout ) )
write the code to a temporary file .