Skip to content

Commit

Permalink
Prevent to append current directory to PATH when launching daemon on …
Browse files Browse the repository at this point in the history
…Windows
  • Loading branch information
ChiaMineJP committed Aug 8, 2024
1 parent 7f51ae1 commit 005020d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion chia/cmds/start_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ def launch_start_daemon(root_path: Path) -> subprocess.Popen:
creationflags = 0
if sys.platform == "win32":
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.CREATE_NO_WINDOW
# On Windows, `shutil.which` appends current directory to PATH if NoDefaultCurrentDirectoryInExePath is unset.
# If current directory is appended, the command tries to execute `...\Chia\Chia.exe` instead of
# `...\Chia\resources\app.asar.unpacked\daemon\chia.exe`
# See https://docs.python.org/3.12/library/shutil.html#shutil.which
os.environ["NoDefaultCurrentDirectoryInExePath"] = "1"

path_helper: Path = Path(sys.argv[0])
cmd_to_execute = shutil.which(cmd=path_helper.name, path=path_helper.parent)
cmd_to_execute = shutil.which(cmd=path_helper.name, path=path_helper.parent, mode=os.X_OK)
if cmd_to_execute is None:
cmd_to_execute = sys.argv[0]

Expand Down

0 comments on commit 005020d

Please sign in to comment.