import subprocess
import os

p12 = "C:\\Users\\jmest\\GolandProjects\\VerifactuMidAPI\\data\\certs\\personal.p12"
pwd = "Mecedora12"
out = "C:\\Users\\jmest\\GolandProjects\\VerifactuMidAPI\\data\\certs\\combined.pem"

cmd = f'openssl pkcs12 -in "{p12}" -passin pass:{pwd} -nodes -out "{out}"'
print(f"Running: {cmd}")

try:
    result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
    print(f"Return code: {result.returncode}")
    if result.returncode != 0:
        print(f"Error: {result.stderr}")
    else:
        print(f"Success! Output: {out}")
        print(f"File size: {os.path.getsize(out)}")
except Exception as e:
    print(f"Exception: {e}")