From 1c13d5a30b09f9687f98f6bcc0e46cc4b57c29a2 Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Sat, 6 Jun 2020 10:37:20 +0200 Subject: [PATCH] Windows EXE: Start Powershell instead of cmd ... if started by file explorer. --- deploy/windows/create_exe.py | 2 +- instaloader/__main__.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/deploy/windows/create_exe.py b/deploy/windows/create_exe.py index 4f60233..33d5928 100644 --- a/deploy/windows/create_exe.py +++ b/deploy/windows/create_exe.py @@ -17,7 +17,7 @@ import subprocess def __main(): with contextlib.suppress(AttributeError, psutil.Error): if psutil.Process().parent().parent().name() == "explorer.exe": - subprocess.Popen("cmd /K \\\"{0}\\\"".format(os.path.splitext(os.path.basename(sys.argv[0]))[0])) + subprocess.Popen("powershell -NoExit -Command \\\"& {0}\\\"".format(sys.argv[0])) return main() diff --git a/instaloader/__main__.py b/instaloader/__main__.py index 6ac3cf5..d59473c 100644 --- a/instaloader/__main__.py +++ b/instaloader/__main__.py @@ -3,6 +3,7 @@ import ast import datetime import os +import platform import re import sys from argparse import ArgumentParser, SUPPRESS @@ -15,10 +16,20 @@ from .instaloader import get_default_session_filename from .instaloadercontext import default_user_agent +def get_simple_argv0() -> str: + if platform.system() != "Windows": + argv0 = os.path.basename(sys.argv[0]) + else: + dirname = os.path.relpath(os.path.dirname(sys.argv[0])) + basename = os.path.basename(sys.argv[0]) + argv0 = os.path.join(dirname, basename) + argv0 = "instaloader" if argv0 == "__main__.py" else argv0 + return argv0 + + def usage_string(): # NOTE: duplicated in README.rst and docs/index.rst - argv0 = os.path.basename(sys.argv[0]) - argv0 = "instaloader" if argv0 == "__main__.py" else argv0 + argv0 = get_simple_argv0() return """ {0} [--comments] [--geotags] {2:{1}} [--stories] [--highlights] [--tagged] [--igtv]