posts - 81, comments - 213, trackbacks - 0

PATH Environment Variable Too Long and Truncated


As I went to append my PATH environment variable on my Windows 7 x64 machine I was surprised by, well perhaps more confused by, not being able to type into the end of the value textbox.

As a reminder, one can edit the PATH variable quickly by

  • Pressing 'Windows Key' + 'Pause Break'
  • 'Advanced system settings' on the left
  • 'Environment Variables' on the lower right corner
  • Selecting 'PATH' under 'System variables'
  • Clicking 'Edit'

Normally I simply click into 'Variable value:' and press the end key to get to the end. Then tack on a semicolon followed by the new path.

This time, however, I could not add more text at the end. I had hit the length limit on the PATH variable. Seriously? Yea…

Apparently you can only key in 2,048 characters. My PATH was already at 2,410, which is oddly larger than 2,048. So perhaps the archaic 'Environment variables' interface is just too strict on the length limits.

First idea

Define PATH using other 'System variables'.

You can modify PATH from the command line with

> SET PATH=%PATH%;C:\My New\Path\

So, perhaps I can define PATH in pieces using other 'System variables'. It turns out you can, and I tried it. I took all of the paths related to development tools and put them into 'DEVPATH'.

I should mention at this point, do the following carefully and at your own risk.

  • Copy the PATH variable value to notepad
  • Keep a copy of the original PATH just in case
  • Move paths in the PATH value to a second line which relate to development (or whatever grouping you like)
  • Be sure that paths are separated by a semicolon
  • Define a new 'System Variable', say 'DEVPATH', and put the extracted paths in the value

 

  • Append ";%DEVPATH%" to the shortened PATH value
  • Edit PATH and set its value to the new shorter value

 

  • Click OK twice to apply the changes

 

Hoping that our PATH variable is now longer and not truncated, I open a new command prompt and echo PATH. Only to find it's truncated in the exact same way. The separation into DEVPATH simply helped to organize the paths… Great, but no fix.

Second idea

Accepting the PATH is limited in length, what to do? Quite simply I had to make it shorter, but I didn't want to break any references.

It turns out a path in PATH includes the directories within the path (sort off). This way we can group and shorten the paths in PATH. I have conveniently separated paths to development applications, those which if broken won't break anything critical, into DEVPATH. Modifying these is then low risk (but again, do at your own risk).

Again editing DEVPATH in notepad, I grouped paths together into 'parent' folders. For example my DEVPATH included

E:\Program Files\Microsoft SQL Server\100\Tools\Binn\;E:\Program Files\Microsoft SQL Server\100\DTS\Binn\;

Which I combined to

E:\Program Files\Microsoft SQL Server;

Doing this enough times my total PATH length was eventually under the limit. Adding my new path to DEVPATH and echoing at the command line confirmed my new path was no longer getting truncated.

Problem solved.

Summary

The short answer is to shorten deep paths to a parent path and remove duplicate paths since the PATH references look within the sub directories. Creating a DEVPATH variable was a convenient way to move the 'low risk' paths out of PATH for liberal modification.

 

 

 

 

 


Print | posted on Monday, August 27, 2012 5:55 PM |

Feedback

Gravatar

# ugg saappaat

Uggs boots keep feet toasty even http://www.uggssaappaatsuomi.org/ in the freezing cold days and ugg saappaat therefore have become the ugg saappaat suomesta first choices of many customers xiaocaicl15. ugg saappaat boots This kind of footwear looks fashionable ugg saappaat oulu and unique and is available in different uggs saarbrücken styles and colors for your choices. Made http://www.uggstovlerdanmark-s.com/ with twin-faced sheepskin, these boots feel incredible ugg boots udsalg warm and comfortable. Many celebrities are ugg boots dk also spotted wearing them during the winter season ugg boots tilbud to go through the cold winter. But this conception is ugg boots online quite wrong, as wearing them sensibly especially with jeans and feathery coats really looks cool and exquisite.
4
11/13/2012 3:14 AM | Zkjykgsng01
Gravatar

# re: PATH Environment Variable Too Long and Truncated

Thanks for the information. Also try Long Path Tool. It helped me with Error 1320 in Win 7. :)
3/8/2013 12:49 PM | GarryBrown
Gravatar

# re: PATH Environment Variable Too Long and Truncated

Not sure how that second option shortening up the path works. I've noticed when I have two paths in the same directory ie( C:\myapps and C:\myapps\otherapps) putting only C:\myapps in the environment path only lets command line see what's in that directory but does not pick up C:\myapps\otherapps so I have to add both of them to the path.

IDK, I'll do some testing.

Thanks for the info and the idea about organizing devpath. I definitely need to do that.

Another option for devtools is to put one devtools directory in the path and in that directory put bat files that call the tools by their full path. I've done that with a few things. It takes some extra work but is similar to how you put executable scripts in usr/bin on a linux system so you don't have to add to the path.
6/7/2013 1:09 PM | Ian
Gravatar

# re: PATH Environment Variable Too Long and Truncated

Could you please let me know, how did you figure out the size of the variable path. Do you have any command for the same.. I am looking for one script , which should display the size of the variable path of environemnt path.

greatly appriciate you help.

Thanks
Ketan
7/15/2013 4:48 AM | Ketan
Gravatar

# re: PATH Environment Variable Too Long and Truncated

I think this whole path-issue is very anoying.
How smart are those guys at Microsoft?
First they come up with something like a path-string.
Then they decide to make the max size only 2400 characters.
To edit it they give you an edit box where you can only see 30 of them.
Then they come with products like SQL-server, and after installing it, half of the path-string is used up.
And if only one postion of this string is mixed up, your software does not work anymore.
How fucking stupid are these people?

1/8/2014 9:32 PM | Nicolas Jacobsen
Gravatar

# re: PATH Environment Variable Too Long and Truncated

Nicolas Jacobsen +1
6/6/2014 10:38 AM | Leandro
Gravatar

# re: PATH Environment Variable Too Long and Truncated

Thanks :) tried the second idea and it works.
6/23/2014 3:07 AM | Shady
Gravatar

# re: PATH Environment Variable Too Long and Truncated

if you are using windows vista or higher, you can make a symbolic link to the folder. for example:

mklink /d C:\pf "C:\Program Files"

would make a link so c:\pf would be your program files folder. I shaved off 300 characters from my path by using this trick.
9/11/2014 3:52 AM | Reza
Gravatar

# re: PATH Environment Variable Too Long and Truncated

hello
you are welcome
You can also use Long Path Tool to sort out this problem.

.......................
9/12/2014 5:08 PM | andrewop
Gravatar

# re: PATH Environment Variable Too Long and Truncated

Another idea is to split the contents of the long path under the PATH variable in the "User Variables" and the PATH variable in the "System Variables". The actual path is the sum of both the PATHs.
9/18/2014 2:38 AM | egovind

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 2 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET