Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem calling an executable with full path #427

Open
joseraffucci opened this issue Jul 17, 2024 · 3 comments
Open

Problem calling an executable with full path #427

joseraffucci opened this issue Jul 17, 2024 · 3 comments

Comments

@joseraffucci
Copy link

I am running into an issue where if I provide a command that has a full path for an executable, for example: "C:\Program Files\Java\jdk-21\bin\java.exe"

It fails to load giving a FileNotFoundError. After investigating the spawn code I found it tries to find the executable in the PATH env variable. While testing the issue, I modified the environment variable PATH to include the location of the executable but this still failed.

To resolve the issue I commented out lines 79-87 of ptyprocess.py:

  path = env.get('PATH', os.defpath)
  command_with_path = which(command, path=path)
  if command_with_path is None:
      raise FileNotFoundError(
          'The command was not found or was not ' +
          'executable: %s.' % command
      )
  command = command_with_path
  argv[0] = command

I am not sure the spawn code should be testing paths against the environment variable PATH and should be left to the code that is calling spawn. This gives more flexibility and also behaves more closely to the subprocess.Popen would. After commenting out this code everything was working as expected.

Another option to the environment PATH testing is if the "which" call returns None, perhaps a call to os.path.exists(command) or os.path.isfile(command) to verify the file exists.

Depending on how you would like the spawn function to behave, I would be glad to create a pull request.

@andfoy
Copy link
Owner

andfoy commented Jul 22, 2024

Pinging @blink1073, since he might know more information about this mechanism

@blink1073
Copy link
Collaborator

I agree with @joseraffucci that we could skip this check and defer to the behavior of subprocess.Popen.

@joseraffucci
Copy link
Author

Understood, I'll update the project code and create a pull request for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants