about summary refs log tree commit diff
path: root/youtube_dl/update.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-09-29 11:26:01 +0200
committerPhilipp Hagemeister <phihag@phihag.de>2013-09-29 14:37:06 +0200
commitd27903703673e565a3a1e8dd418d1347ef331b3e (patch)
treefeaf87d0cd1053aeba9f4d139d717df5e8f612f2 /youtube_dl/update.py
parent46353f6783b9e468c9271c864f0711c85d3cea33 (diff)
downloadyoutube-dl-d27903703673e565a3a1e8dd418d1347ef331b3e.tar.gz
youtube-dl-d27903703673e565a3a1e8dd418d1347ef331b3e.tar.xz
youtube-dl-d27903703673e565a3a1e8dd418d1347ef331b3e.zip
[update] Prevent cmd window popup on Windows (Fixes #1478)
Diffstat (limited to 'youtube_dl/update.py')
-rw-r--r--youtube_dl/update.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/youtube_dl/update.py b/youtube_dl/update.py
index 669b59a68..0689a4891 100644
--- a/youtube_dl/update.py
+++ b/youtube_dl/update.py
@@ -1,6 +1,8 @@
+import io
 import json
 import traceback
 import hashlib
+import subprocess
 import sys
 from zipimport import zipimporter
 
@@ -75,8 +77,9 @@ def update_self(to_screen, verbose):
         to_screen(u'ERROR: the versions file signature is invalid. Aborting.')
         return
 
-    to_screen(u'Updating to version ' + versions_info['latest'] + '...')
-    version = versions_info['versions'][versions_info['latest']]
+    version_id = versions_info['latest']
+    to_screen(u'Updating to version ' + version_id + '...')
+    version = versions_info['versions'][version_id]
 
     print_notes(to_screen, versions_info['versions'])
 
@@ -122,16 +125,18 @@ def update_self(to_screen, verbose):
 
         try:
             bat = os.path.join(directory, 'youtube-dl-updater.bat')
-            b = open(bat, 'w')
-            b.write("""
-echo Updating youtube-dl...
+            with io.open(bat, 'w') as batfile:
+                batfile.write(u"""
+@echo off
+echo Waiting for file handle to be closed ...
 ping 127.0.0.1 -n 5 -w 1000 > NUL
-move /Y "%s.new" "%s"
-del "%s"
-            \n""" %(exe, exe, bat))
-            b.close()
+move /Y "%s.new" "%s" > NUL
+echo Updated youtube-dl to version %s.
+start /b "" cmd /c del "%%~f0"&exit /b"
+                \n""" % (exe, exe, version_id))
 
-            os.startfile(bat)
+            subprocess.Popen([bat])  # Continues to run in the background
+            return  # Do not show premature success messages
         except (IOError, OSError) as err:
             if verbose: to_screen(compat_str(traceback.format_exc()))
             to_screen(u'ERROR: unable to overwrite current version')