Skip to content

Double-click launching a script sets working directory to System32 #134

Closed
@DavidCEllis

Description

@DavidCEllis

Describe the bug
With the previous py launcher installed, double clicking on a script in file explorer launched the script with the working directory set to the folder the script was in.

With the new launcher included with pymanager the working directory is set to C:\Windows\System32.

Launching from the shell gives the shell working directory as expected.

I'm not aware of this being an intentional change.

To Reproduce
Create a script that prints os.getcwd(), eg:

import os
print(os.getcwd())
input("Waiting for input to close")

With the new launcher associated with .py files
Launch the script by double-clicking the .py file icon.

Expected behavior
Scripts launched by double-clicking in explorer should have their working directory as the folder the script is in as with the previous launcher.

Additional context
Originally I found this by the change in behaviour with a zipapp that launches a shell via subprocess as with the new launcher this put me in system32 instead of the folder I expected.

Something along these lines:

import shutil
import subprocess

shell = (
    shutil.which("pwsh.exe") 
    or shutil.which("powershell.exe")
    or shutil.which("cmd.exe")
)

subprocess.run([shell])

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions