main: Execute sys.argv[0] on Windows

On Windows, sys.argv[0] is the path to an executable (.exe) instead of
a Python script. Execute that file directly instead of relying on
Python to do so.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
Carles Cufi 2019-02-04 21:16:26 +01:00 committed by Carles Cufí
parent 18f6e55bda
commit e2022c6f02
1 changed files with 7 additions and 1 deletions

View File

@ -505,6 +505,12 @@ def main(argv=None):
except WestUpdated: except WestUpdated:
# West has been automatically updated. Restart ourselves to run the # West has been automatically updated. Restart ourselves to run the
# latest version, with the same arguments that we were given. # latest version, with the same arguments that we were given.
log.dbg("sys.executable:\"{}\" sys.argv[0]:\"{}\" argv:\"{}\"".format(
sys.executable, sys.argv[0], argv))
if sys.platform == "win32":
# On Windows Python generates .exe executables
os.execv(sys.argv[0], argv)
else:
os.execv(sys.executable, [sys.executable] + [sys.argv[0]] + argv) os.execv(sys.executable, [sys.executable] + [sys.argv[0]] + argv)
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit(0) sys.exit(0)