What am I doing wrong?
muellerkyle opened this issue · comments
C:\>npm install -g which
C:\Users\%USER%\AppData\Roaming\npm\which -> C:\Users\%USER%\AppData\Roaming\npm\node_modules\which\bin\which
C:\Users\%USER%\AppData\Roaming\npm
└─┬ which@1.2.0
└─┬ is-absolute@0.1.7
└── is-relative@0.1.3
C:\>which java
C:\>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
This is on windows 7 pro.
Am I missing something important about how this library operates? I'm attempting to install another module that uses which (selenium-standalone) and it's failing on a java check. I cannot for the life of me determine why, as I have it in my path (as demonstrated by my version check).
Seems to work for me:
C:\Program Files>node --version
v0.10.32
C:\Program Files>which node
'which' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files>which node
'which' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files>npm i -g which
C:\Program Files\nodejs\which -> C:\Program Files\nodejs\node_modules\which\bin\
which
which@1.2.0 C:\Program Files\nodejs\node_modules\which
└── is-absolute@0.1.7 (is-relative@0.1.3)
C:\Program Files>which node
C:\Program Files\nodejs\node.EXE
Is it perhaps using a different which
? What happens when you type which which
?
C:\>which which
C:\Users\%USER%\AppData\Roaming\npm\which.CMD
Oddly enough, which node is returned blank too.
C:\>which node
C:\>
But, this works:
C:\>node --version
v4.2.2
C:\>
Try this:
echo %PATH%
node -p process.execPath
Thanks.
C:\>echo %PATH%
D:\Product\TerminalEmulators\cmder\cmder_1.2.1\vendor\conemu-maximus5;D:\Product\TerminalEmulators\cmder\cmder_1.2.1\vendor\conemu-maximus5\ConEmu;"D:\Product\nano\nano";"C:\Windows\system32";"C:\Windows";"C:\Windows\system32\wbem";"C:\Windows\System32\WindowsPowerShell\v1.0";"C:\Program Files\TortoiseSVN\bin";"C:\Windows\SUA\common";"C:\Windows\SUA\usr\lib";"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin";"C:\Program Files\SlikSvn\bin";"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\";"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\";"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\";"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\";"C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\";"C:\Program Files\Microsoft SQL Server\100\DTS\Binn\";"C:\Python27";"C:\Windows\System32\WindowsPowerShell\v1.0\";"C:\Program Files\SourceGear\Common\DiffMerge\";"C:\Program Files\Microsoft\Web Platform Installer\";"C:\Program Files\Sublime Text 3";"C:\Program Files (x86)\Git\cmd";"c:\Program Files\Oracle\VirtualBox\";"C:\Program Files\Perforce";"C:\Program Files (x86)\Bitvise SSH Client";"C:\Program Files\nodejs\";"C:\Program Files (x86)\nodejs\";"C:\HashiCorp\Vagrant\bin";"C:\Program Files\Boot2Docker for Windows";"C:\Program Files (x86)\Git\bin";"C:\ProgramData\chocolatey\bin";"C:\Program Files\Mercurial\";"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin";"D:\Product\MingW\mingw64\bin";"D:\Product\MingW\mingw64\libexec\gcc\x86_64-w64-mingw32\4.9.1";"C:\Program Files (x86)\GitExtensions\";"C:\Go\bin";"C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\";"C:\Program Files (x86)\Notepad++\";"C:\Program Files\Oracle\VirtualBox";"D:\Product\redis\Redis_2_4_11\x64";D:\Product\Javascript Frameworks\JSLint\jsl-0.3.0-win32\jsl-0.3.0;C:\Users\%user%\AppData\Local\atom\bin;"C:\Users\%user%\go\bin";"C:\Go\bin";C:\msysgit\git;C:\Users\%user%\AppData\Roaming\npm
C:\>node -p process.execPath
C:\Program Files (x86)\nodejs\node.exe
That's what I get. Apologies for how messy that is. Also, I replaced my domain account with %user% so that it's not posted here. But, other than that, that output is unedited.
I was interested that C:\Program Files\Java\jre1.8.0_40\bin
was absent from that path output.
I added it to the beginning of my system path, but I still receive the same output
C:\>which java
C:\>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
So, that doesn't appear to be the issue.
Note that if you change an environment variable you usually have to restart the command prompt, or in some cases, restart the computer. (Since this is windows.)
I'm aware of that issue and restarted the terminal (command prompt) between changes.
I'm no longer at the office, but I'll attempt to step through the which code on Monday to see if I can find the issue.
Thanks Isaac
I'm still digging into this, but this is the first thing that I've run into.
I created a test app.js which makes a which call and then did a break down into the which.js src.
On line 80, p is being set to:
'D:\\Proto\\whichTest\\"C:\\Program Files\\Java\\jre1.8.0_40\\bin"\\java'
Which is a concatenation of the test directory and the actual directory that java resides in.
I'm still digging around and hope to find where it's going awry momentarily.
Maybe the isAbsolute library isn't processing the test path correctly?
No, the issue isn't the isAbsolute call. I see now that you only use that for a test on what's passed in for the command argument.
The issue, appears to be how node's path.resolve handles double quotes.
I replaced line 80 of the current source, which is:
var p = path.resolve(pathEnv[i], cmd)
with
var p = isWindows ? path.resolve(pathEnv[i].replace(/"/g,""), cmd) : path.resolve(pathEnv[i], cmd);
and before line 108, I added a new variable for clean path (cP) so that:
var p = path.join(pathEnv[i], cmd)
reads:
var cP = isWindows ? pathEnv[i].replace(/"/g,"") : pathEnv[i];
var p = path.join(cP, cmd)
This fixed the issue for me. If you're okay with my solution, I can create a pull request. Or, if you want to just make a change, I'm okay with that too.
Ah! Great digging on this, thanks! So, the issue is having something in the env.PATH
that is quoted.
I'd rather replace it at each step, instead of all at once like suggested here.
Can you try this patch and see if it fixes your issue? https://gist.github.com/isaacs/271f41848f5782fba70a
I'll give it a try and let you know the results.
I wonder if it's possible to have a ;
in a file name if it's quoted, on Windows. That could make this break really interestingly. Also, if you have "
in a folder name, how does that show up in the Path environ?
The pathPart.substr(1,-1)
doesn't return the parts of the string that we need.
I believe that you want: pathPart.slice(1, -1)
With that change to both places where you assign pathPart, the patch works for me.
Right, slice, not substr.
I'll write up a test and land this in the next day or two. If you want it to land sooner, you can write the test and send as a PR. (Feel free to steal my work, especially since you actually just made it work ;)
As far as semi-colons go, it does appear that they are valid for file names per this MSDN article. Double quotes are reserved though, and would not normally be in a directory or file name.
No, in a day or two is fine. I appreciate your help and the library. Thanks!
Note: I ran into this while attempting to use selenium-standalone, which suffers from this if you use quoted directories in your path. So, I'll let them know of the update when you do push out the change.
This should be working on the latest release.
Thank you!