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

Incorrect behavior running executable if current location path is longer than 256 characters #13955

Open
sba923 opened this issue Oct 31, 2020 · 8 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Comments

@sba923
Copy link
Contributor

sba923 commented Oct 31, 2020

Steps to reproduce

If the path to the current location is > 256 characters, running an executable from PowerShell either fails or works but the executable is run in a separate console.

PS> pwd; (pwd).Path.Length
Path
----
C:\Users\steph\OneDrive\test\test01\test02\test03\test04\test05\test06\test07\test08\test09\test10\test11\test12\test13\test14\test15\test16\test17\test18\test19\test20\test21\test22\test23\test24\test25\test26\test27\test28\test29\tes…
245
PS> HelloCsharpWorld.exe
Hello, C# world!
PS> cd test32
PS> pwd; (pwd).Path.Length
Path
----
C:\Users\steph\OneDrive\test\test01\test02\test03\test04\test05\test06\test07\test08\test09\test10\test11\test12\test13\test14\test15\test16\test17\test18\test19\test20\test21\test22\test23\test24\test25\test26\test27\test28\test29\tes…
252
PS> HelloCsharpWorld.exe
Hello, C# world!
PS> cd test33
PS> pwd; (pwd).Path.Length
Path
----
C:\Users\steph\OneDrive\test\test01\test02\test03\test04\test05\test06\test07\test08\test09\test10\test11\test12\test13\test14\test15\test16\test17\test18\test19\test20\test21\test22\test23\test24\test25\test26\test27\test28\test29\tes…
259
PS> HelloCsharpWorld.exe
ResourceUnavailable: Program 'HelloCsharpWorld.exe' failed to run: The directory name is invalid.At line:1 char:1
+ HelloCsharpWorl …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
PS> cd test34
PS> pwd; (pwd).Path.Length
Path
----
C:\Users\steph\OneDrive\test\test01\test02\test03\test04\test05\test06\test07\test08\test09\test10\test11\test12\test13\test14\test15\test16\test17\test18\test19\test20\test21\test22\test23\test24\test25\test26\test27\test28\test29\tes…
266
PS> HelloCsharpWorld.exe
(no output, executable is run in a separate console that self-closes)

Expected behavior

Running an executable should work and output to the current console, whatever the current location.

Actual behavior

If the path to the current location is > 256 characters long, running an executable either fails or is done in a separate console, yielding no output in the current console.

Environment data

> $psversiontable

Name                           Value
----                           -----
PSVersion                      7.1.0-rc.2
PSEdition                      Core
GitCommitId                    7.1.0-rc.2
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@sba923 sba923 added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Oct 31, 2020
@jborean93
Copy link
Collaborator

I think this may be an actual limitation in CreateProcess. When querying info about setting the current directory that exceeds MAX_PATH I got back this info MicrosoftDocs/feedback#1441.

@sba923
Copy link
Contributor Author

sba923 commented Oct 31, 2020

Seems a valid reason. But shouldn't PowerShell warn about it / yield a well-defined error if this is attempted?

@jborean93
Copy link
Collaborator

Sure, just wanted to share some background info that seemed to be relevant.

@iSazonov iSazonov added the WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc. label Oct 31, 2020
@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
@karlhorky
Copy link

Interesting, is there still a problem with launching programs from long paths in PowerShell, even when LongPathsEnabled is set to 1? (longer than the 260 character MAX_PATH limit)

As part of my research into Node.js support of long paths on Windows I've experienced that running node -v just errors out with The directory name is invalid (Windows 11 Pro x64 machine with LongPathsEnabled is set to 1):

PS C:\> node -v
v20.5.1

PS C:\> mkdir long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\


    Directory: C:\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\l
    ong-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-p
    ath\long-path\long-path\long-path\long-path


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        17.11.2023     16:27                long-path


PS C:\> cd long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\
PS C:\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path\long-path> node -v
Program 'node.exe' failed to run: The directory name is invalidAt line:1 char:1
+ node -v
+ ~~~~~~~.
At line:1 char:1
+ node -v
+ ~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

More details over here:

@karlhorky
Copy link

I can also open a new issue if that would be better, since this is not 100% the same issue...

cc @iSazonov

@sba923
Copy link
Contributor Author

sba923 commented Nov 28, 2023

The problem repro'es with 7.4.0 on Windows 11 build 10.0.22621.2715.amd64fre.ni_release.220506-1250

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 28, 2023
@karlhorky
Copy link

karlhorky commented Dec 8, 2023

@iSazonov @jborean93 @daxian-dbw @SteveL-MSFT can this issue be reopened? I think it should not be closed.

@iSazonov iSazonov reopened this Dec 9, 2023
@LesFerch
Copy link

This issue appears to apply to ALL executables. Here, I'm just trying to run whoami in PowerShell opened to a long path:

image

I can open Cmd to the same folder and have no problem running the same Exe. It's ironic that the ancient Cmd.exe is more capable in this regard:

image

And yes, that really is the same folder. It's more clear if I change my PowerShell prompt to 8.3 format. Of course, that does nothing to fix the problem:

image

And, finally, before anyone asks; Yes, LongPathsEnabled is already set to 1 (enabled).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Projects
None yet
Development

No branches or pull requests

5 participants