Comments (4)
That's what cd -e
does:
C:\>cd -?
Chdir 1.80
Build 20221126
Changes the current directory.
CHDIR [-e] [-license] <directory>
-e Change to an escaped long path
C:\>cd -e c:\
\\?\C:\>cd c:\
C:\>
As you noted, this has (bad) compatibility consequences. CMD will interpret these current directories as UNC, which means it automatically change directory to \Windows
when launched with one of these active. That breaks all .bat
and .cmd
scripts. This is why Yori uses prefixed long paths internally for almost everything, except for this, and why I didn't want to silently use prefixed long paths in this specific case. As you say, Yori tools should work, although since this isn't the default operation I haven't tested them in a while.
from yori.
Unfortunately when testing cd -e
I still cannot set a long path name as current directory.
If the path name is short enough then it works. and I see the nice \\?\
prefix
For example I get after cd -e:
chdir: could not change directory: \\?\D:\12345678\12345678901234567890123456789
01234567890\1234567890123456789012345678901234567890\123456789012345678901234567
8901234567890\1234567890123456789012345678901234567890\1234567890123456789012345
678901234567890\123456789012345678901234567890\123456789012345678901234567890: T
he filename or extension is too long.
Maybe this is because I use Old windows Server 2003? Windows 7 also gets this problem (I just checked).
I was not sure of what the -e parameter meant because indeed it made no difference when trying to chdir in a long path name. Sorry I forgot to mention that. Or maybe you mean something else?
from yori.
Ouch, you're right, it looks like -e
is basically useless.
As far as I can tell:
- Old versions of Windows (pre-10) always allocate current directory using a fixed size buffer that's MAX_PATH in size. This size is actually a value in the PEB, so it's possible to change, which works...except any child process doesn't have the change so if the parent process uses this to force a long path it can't spawn any child until current directory is changed to something shorter.
- As part of the long path changes, Windows 10 attempted to fix this, but the initial attempts didn't account for all characters correctly and weren't correct.
- Newer versions of Windows 10 got this "right" except they only invoke this behavior when long path support is enabled, even though these prefixed paths are conceptually independent of that and are supposed to be an alternative.
Currently the only way I could see this working is to temporarily reset current directory before launching a child, launch the child with debugging enabled, and patch the child's memory to contain the correct current directory and buffer lengths. The problem with doing this is it needs to be recursive - when the child wants to launch another child, that needs to be fixed up too, but CreateProcess
fails if the current directory isn't restored before it's called, so the debugger would need to intercept calls to CreateProcess
to perform the necessary fixups. Note in particular that the child can be launched either with an explicit current directory or inheriting its parent's current directory, so this requires breaking on CreateProcess
, inspecting the arguments and parent state, intercepting the return from CreateProcess
(to restore parent state) and applying the saved state to the child on its initial break.
In other words, I'm not sure it's worth pursuing :) Yori already has code to be a debugger in certain cases, but this seems like the most invasive case yet.
from yori.
In other words, I'm not sure it's worth pursuing :) Yori already has code to be a debugger in certain cases, but this seems like the most invasive case yet.
I agree it would be too much trouble.
Current directory was always limited even with UNC because it is legacy from unix/dos and NT api only uses absolute paths. So I guess we are mostly out of luck.
Maybe the cd -s
switch could be used to use the short path so that when a path is just a bit too long we could still chdir inside.
This would be a simple workaround, far from perfect of course.
the short path also has the advantage to only have ascii characters and no spaces which is also helpful when invoking non-Unicode and/or non spaces aware programs. I used to use a shortened launcher for several programs that were just stupid.
from yori.
Related Issues (20)
- Ctrl-C stops working after terminating GUI app once HOT 5
- Provide all installer options as command line arguments HOT 2
- Allow for a custom starting directory HOT 2
- Command line length limit in Yori ? Like 8191 in cmd ? HOT 2
- Broken alias command for paths with spaces HOT 2
- Feature request: Option in Tee to remove color HOT 2
- yori's lsof breaks react-scripts HOT 3
- Yori installer for the arm64 Windows HOT 4
- current version -- 2.0 is marked as infected with a trojan by Windows Defender HOT 3
- yenv: accept variable from stdin HOT 4
- "cab.exe -s -u" does not overwrite files with read-only and system attributes set HOT 2
- "ycopy.exe -p" raises ERRORLEVEL to 1 if there is nothing to overwrite HOT 1
- Can't run Notepad HOT 2
- YoriInit.ys1 script %__APPDIR__% and %__CD__% environment variables on Windows XP HOT 2
- throw er; // Unhandled 'error' event HOT 2
- fail to install yori-core on amd HOT 2
- ConEmu + Clink + Yori + Python + xonsh = surprise XD HOT 2
- CD Improvement HOT 2
- feature request: DIR /W multi-column filename-only view HOT 2
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 yori.