Git Product home page Git Product logo

Comments (4)

andfoy avatar andfoy commented on September 6, 2024

Hi @Stefanhg, thanks for reaching out. The cwd parameter is used to initialize the path from where the program will start from. That is, different from the actual location of the binary to execute, which should be available in the PATH. In order to execute your program properly in your example, you can either specify the full path to the binary as C:\<long path comes here>\my_folder\my_exe_file.exe or add my_folder to PATH.

Please let me know if this works for you

from pywinpty.

Stefanhg avatar Stefanhg commented on September 6, 2024

Hello @andfoy,
This ended up raising more questions for me as I am really unsure how this actually work.

So the way cwd is implemented here is cwd is actually the path that will be set as working path when executable is executed?
If so, then I guess It is just one of those "if documented, no problems" cases. It has just been confusing me so much as I expected cwd to yield the same result as adding path_to_my_folder to PATH.

I did get it to work by adding path_to_my_folder to PATH but i still don't see how the implementation of cwd is supposed to be useful if you cannot use it to set path_to_my_folder before executing.

It is the only thing I found while using this tool. It works SO WELL for the testing I was doing! I'm glad I came across this!

from pywinpty.

andfoy avatar andfoy commented on September 6, 2024

@Stefanhg First of all, I'm glad this library works for you! Second, here is a much lengthy explanation about the behaviour for the cwd argument:

According to the CreateProcessW Windows API documentation, the resolution of an executable occurs as follows:

  1. The directory from which the application loaded.
  2. The current directory for the parent process.
  3. The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
  4. The 16-bit Windows system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.
  5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  6. The directories that are listed in the PATH environment variable. Note that this function does not search the per-application path specified by the App Paths registry key. To include this per-application path in the search sequence, use the ShellExecute function.

For documentation purposes, the cwd command is being mapped internally into the lpCurrentDirectory argument, which specifies:

The full path to the current directory for the process. The string can also specify a UNC path.

It is worthy to note that there is not a step in the aforementioned process where the lpCurrentDirectory argument is used to resolve an executable path. Thus making this library compliant with the Windows API spec.

While the confusion regarding program search paths is understandable, the current behavior is the built-in one in Windows, and given the long confusing process used to search a path described above, it is most recommended to either specify the full path to a binary or add it into the PATH.

I hope this explanation clears the confusion.

from pywinpty.

Stefanhg avatar Stefanhg commented on September 6, 2024

Ah okay now I understand. Thank you for clarifying!

When i was trying to get it all working I was also initially using the full path when executing and it is also my preferred method but It ended up not working in some way and after some time I just ditched it and tried to find alternative solutions.
Now I am looking at again I think I did resolve the issue which was mainly me forgetting to pass the string as a raw.. Typical!

I guess I can close this issue. It is just me having a different idea of how it works and a solution for my problem already exists in two ways as shown in your first comment

from pywinpty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.