Comments (4)
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.
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.
@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:
- The directory from which the application loaded.
- The current directory for the parent process.
- The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory.
- 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.
- The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
- 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.
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)
- Release v2.0.2
- Release v2.0.3
- ConPTY is not fully working in CI HOT 4
- Build failure on windows py3.6 HOT 1
- Release v2.0.4
- Release v2.0.5
- Async read?
- Release v2.0.6
- Release v2.0.7
- Garbled output on Telnet Client HOT 10
- Release v2.0.8
- Failed to install with python 3.11 HOT 2
- 'Pty is closed.' BUG
- Release v2.0.10
- ssh connection establish failed.
- How do I get the same functionality as pty.spawn? HOT 6
- [Question] Messed up display buffer after resize? HOT 2
- Question: Does `PTY.write()` take in unicode string or bytes?
- Freeze on process.iseof() HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywinpty.