Skip to content

Commit 230e6a9

Browse files
authored
Fix the fix of the fix (#1454)
Signed-off-by: paul.profizi <[email protected]>
1 parent caa116d commit 230e6a9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/ansys/dpf/core/server_types.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import os
1010
import socket
1111
import subprocess
12-
import sys
1312
import time
1413
import warnings
1514
import traceback
1615
from threading import Thread, Lock
1716
from abc import ABC
17+
from ctypes import *
1818

1919
import psutil
2020

@@ -928,10 +928,17 @@ def __init__(
928928
self.set_as_global(as_global=as_global)
929929
# Update the python os.environment
930930
if not os.name == "posix":
931-
new_path = subprocess.check_output(
932-
[sys.executable, "-c", r'import os; print(os.environ["PATH"])'], text=True
933-
) # pragma: no cover
934-
os.environ["PATH"] = new_path
931+
# Forced to use ctypes to get the updated PATH due to sys.exec not the Python
932+
# interpreter when running Python plugin test VS project
933+
# The better solution would be to not need to update the path
934+
windll.kernel32.GetEnvironmentVariableA.argtypes = (c_char_p, c_char_p, c_int)
935+
windll.kernel32.GetEnvironmentVariableA.restype = c_int
936+
name = "PATH"
937+
b_name = name.encode("utf-8")
938+
size = 32767
939+
buffer = create_string_buffer(b"", size)
940+
_ = windll.kernel32.GetEnvironmentVariableA(b_name, buffer, size)
941+
os.environ["PATH"] = buffer.value.decode("utf-8")
935942

936943
@property
937944
def version(self):

0 commit comments

Comments
 (0)