fix: use subprocess instead of os.popen for andreal calling

This commit is contained in:
283375 2023-10-01 02:47:16 +08:00
parent bce48a03a7
commit de8c5d28a7
Signed by: 283375
SSH Key Fingerprint: SHA256:UcX0qg6ZOSDOeieKPGokA5h7soykG61nz2uxuQgVLSk
2 changed files with 16 additions and 9 deletions

View File

@ -2,6 +2,7 @@ import base64
import logging
import os
import re
import subprocess
from PySide6.QtCore import QObject, QProcess, QRunnable, QThreadPool, Signal
@ -24,7 +25,12 @@ class AndrealExecuteRunnable(QRunnable):
def run(self):
try:
result = os.popen(f"{self.executePath} {' '.join(self.arguments)}").read()
subp = subprocess.run(
[self.executePath, *self.arguments],
capture_output=True,
encoding="utf-8",
)
result = subp.stdout
b64Result = [s for s in result.split("\n") if s]
imageBytes = base64.b64decode(
re.sub(r"data:image/.*;base64,", "", b64Result[-1])

View File

@ -180,19 +180,20 @@ class TabTools_Andreal(Ui_TabTools_Andreal, QWidget):
arguments = [
str(self.imageType()),
f'--json-file="{jsonFile}"',
f"--img-version={self.imageVersion()}",
"--json-file",
jsonFile,
"--img-version",
str(self.imageVersion()),
]
if self.andrealFolderSelector.selectedFiles():
arguments.append(
f'--path="{self.andrealFolderSelector.selectedFiles()[0]}"'
)
arguments.append("--path")
arguments.append(self.andrealFolderSelector.selectedFiles()[0])
if preview:
arguments.extend(["--img-format=jpg", "--img-quality=20"])
arguments.extend(["--img-format", "jpg", "--img-quality", "20"])
else:
arguments.append(f"--img-format={self.imageFormat()}")
arguments.extend(["--img-format", self.imageFormat()])
if self.imageFormat() == "jpg":
arguments.append(f"--img-quality={self.jpgQualitySpinBox.value()}")
arguments.extend(["--img-quality", str(self.jpgQualitySpinBox.value())])
return arguments
def getAndrealJsonContent(self):