From 771ceaeefc8cfc07e06fdc0c7d63ee078f4a7fbd Mon Sep 17 00:00:00 2001 From: J1uShan9 Date: Sat, 22 Jun 2024 00:25:38 +0800 Subject: [PATCH 1/4] try fix cmd check --- util/Data/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util/Data/__init__.py b/util/Data/__init__.py index 0b6f794..b03a0bb 100644 --- a/util/Data/__init__.py +++ b/util/Data/__init__.py @@ -2,7 +2,7 @@ import datetime import json import os -from sys import exit +from sys import argv, exit from time import sleep import inquirer @@ -60,12 +60,15 @@ def QRGenerate(self, url: str, img_path: str) -> None: parent_pid = psutil.Process(os.getpid()).ppid() parent_process = psutil.Process(parent_pid) parent_name = parent_process.name() + parent_env = parent_process.environ() except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): - parent_name = "" + logger.error("获取父进程信息失败!") + sleep(5) + exit() if parent_name == "powershell.exe" or "WT_SESSION" in os.environ: qr.print_ascii(invert=True) - elif parent_name == "cmd.exe": + elif parent_name == "cmd.exe" or len(argv) == 1: img.show() else: qr.print_ascii(invert=True) From 802f5b8cefd2f353aafa679c7a0b92aa18ce6197 Mon Sep 17 00:00:00 2001 From: J1uShan9 Date: Sat, 22 Jun 2024 00:27:48 +0800 Subject: [PATCH 2/4] try fix cmd check --- util/Data/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/util/Data/__init__.py b/util/Data/__init__.py index b03a0bb..0592704 100644 --- a/util/Data/__init__.py +++ b/util/Data/__init__.py @@ -65,12 +65,14 @@ def QRGenerate(self, url: str, img_path: str) -> None: logger.error("获取父进程信息失败!") sleep(5) exit() - - if parent_name == "powershell.exe" or "WT_SESSION" in os.environ: - qr.print_ascii(invert=True) - elif parent_name == "cmd.exe" or len(argv) == 1: - img.show() - else: + if os.name == "nt": + if parent_name == "powershell.exe" or "WT_SESSION" in os.environ: + qr.print_ascii(invert=True) + elif parent_name == "cmd.exe" or len(argv) == 1: + img.show() + else: + qr.print_ascii(invert=True) + elif os.name == "posix": qr.print_ascii(invert=True) @logger.catch From dedd4376ffbcfc09523f8f20f560b19d3a0c1a6d Mon Sep 17 00:00:00 2001 From: J1uShan9 Date: Sat, 22 Jun 2024 00:38:00 +0800 Subject: [PATCH 3/4] try fix cmd check --- util/Data/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/Data/__init__.py b/util/Data/__init__.py index 0592704..c9fd896 100644 --- a/util/Data/__init__.py +++ b/util/Data/__init__.py @@ -60,7 +60,7 @@ def QRGenerate(self, url: str, img_path: str) -> None: parent_pid = psutil.Process(os.getpid()).ppid() parent_process = psutil.Process(parent_pid) parent_name = parent_process.name() - parent_env = parent_process.environ() + print(argv) except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess): logger.error("获取父进程信息失败!") sleep(5) @@ -68,7 +68,7 @@ def QRGenerate(self, url: str, img_path: str) -> None: if os.name == "nt": if parent_name == "powershell.exe" or "WT_SESSION" in os.environ: qr.print_ascii(invert=True) - elif parent_name == "cmd.exe" or len(argv) == 1: + elif parent_name == "cmd.exe" or len(argv) == 1 and not argv[0].endswith(".py"): img.show() else: qr.print_ascii(invert=True) From e21d2fd2200be4a8933ca44f1f2cb9bc4d948ae3 Mon Sep 17 00:00:00 2001 From: J1uShan9 Date: Sat, 22 Jun 2024 00:40:46 +0800 Subject: [PATCH 4/4] try fix cmd check --- util/Data/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/Data/__init__.py b/util/Data/__init__.py index c9fd896..1dcd25f 100644 --- a/util/Data/__init__.py +++ b/util/Data/__init__.py @@ -72,7 +72,7 @@ def QRGenerate(self, url: str, img_path: str) -> None: img.show() else: qr.print_ascii(invert=True) - elif os.name == "posix": + else: qr.print_ascii(invert=True) @logger.catch