cmderdev / cmder

Lovely console emulator package for Windows
https://cmder.app
MIT License
25.91k stars 2.03k forks source link

Question: How to fix "find: ‘\\cmd\\git.exe’: No such file or directory"? #2766

Closed d4k0 closed 2 years ago

d4k0 commented 2 years ago

Question

Hi,

I just updated to 1.3.20 and now I get the message "find: ‘\cmd\git.exe’: No such file or directory" every time I start Cmder. I also tried a fresh portable installation, but the same thing is observed there. Is this a bug?

2022-10-18_21-57-58

Checklist

DRSDavidSoft commented 2 years ago

Hi there, thanks for reporting this issue.

This is related to the following line of code: https://github.com/cmderdev/cmder/blob/2acb6808edfd9ea65d8b68cd7085992a7b4e6ca4/vendor/init.bat#L244

I'm not sure specifically why updating Cmder to 1.3.20 caused this issue, but the reason is because the unix find.exe is overwriting the windows find.exe in PATH, and since they do completely different things (one finds a file and the other finds a substring in text) they are not compatible.

I'll work on a fix right away, but in the meantime please open Command Prompt, cd to cmder root and try this command to see if the issue is resolved:

vendor\init.bat /nix_tools 0

if so, I'll make an update to the project that will resolve this issue. You'll need to download only the vendor\init.bat file from GitHub and replace it in your Cmder directory.

Thanks! 😄

DRSDavidSoft commented 2 years ago

Added a workaround in https://github.com/cmderdev/cmder/commit/8b6d1d8a6f0f88cf50f81c942aa193a261f7051c

@daxgames Can you please have a look and test?

d4k0 commented 2 years ago

@DRSDavidSoft Thanks for the quick answer. Unfortunately, that doesn't seem to have worked:

2022-10-18_23-54-07

daxgames commented 2 years ago

@DRSDavidSoft 👍

Simple fully qualified path to find like %windir%\system32\find ..... would have worked too and may have been easier write and follow. :-)

DRSDavidSoft commented 2 years ago

@daxgames Ok, should I revert to using find.exe instead, with the fully qualified path?

This was meant to not rely on using external executables, which could potentially slow down the init process.

chrisant996 commented 2 years ago

This line in the commit looks like it will fail when %full_path% contains spaces:

if not [\%full_path:\cmd\git.exe=:%]==[\%full_path%] (

@daxgames Ok, should I revert to using find.exe instead, with the fully qualified path?

This was meant to not rely on using external executables, which could potentially slow down the init process.

The fewer external executables and call commands, the better!!! Both of those can significantly slow down the init process.

DRSDavidSoft commented 2 years ago

@chrisant996 I just did a test and it seems that due to using double quotes, the space might not be an issue:

@echo off

setlocal enabledelayedexpansion

for /F "delims=" %%F in ('where code.cmd 2^>nul') do call :check_code "%%~fF"

:check_code
    set full_path="%~f1"
    if not defined CODE_INSTALL_ROOT (
        if not [\%full_path:\bin\code.cmd=:%]==[\%full_path%] (
            echo Executing "%~df1" --version
            "%~df1" --version
        )
    ) else (
        echo Skipping %full_path%
    )
    exit /b
Executing "C:\Program Files\Microsoft VS Code\bin\code.cmd" --version
1.70.2
e4503b30fc78200f846c62cf8091b76ff5547662
x64

In any case, I'm wondering which route is the better way to go, using a call :sub_routine to check substrings with if and string substitution, or using find.exe (with the fully qualified path) to filter out lines, and not use a subroutine.

Please feel free to do some tests and use the method that suits best. Thanks! 😄

DRSDavidSoft commented 2 years ago

@d4k0 Please follow these steps to see if the issue is resolved:

  1. Open the Cmder that you've downloaded
  2. Paste this command in full:
    curl "https://raw.githubusercontent.com/cmderdev/cmder/master/vendor/init.bat" > %CMDER_ROOT%\vendor\init.bat
  3. Wait for the command to finish, and take a screenshot so you can post it here
  4. Exit Cmder then Restart it
  5. Check if the issue persists.

Please report back if this solves the issue.

chrisant996 commented 2 years ago

@chrisant996 I just did a test and it seems that due to using double quotes, the space might not be an issue:

...
    set full_path="%~f1"
...

I see now. I hadn't looked closely enough. Out of curiosity, what is the reason for the surrounding [..]? Since %full_path% already contains quotes, the \ before the %full_path% on each side looks like there isn't a functional need for the [..], and I made a bad assumption that they were meant to function similar to quotes. But 2 lines earlier there are clearly quotes, I just didn't look far enough, sorry!

DRSDavidSoft commented 2 years ago

The brackets were used mainly for two reasons:

  1. Avoid an issue where an empty string would fail the comparison
  2. Better code readability

However, I guess using the \ prefix invalidates both reasons, so I'll remove them.

Thanks for taking a closer look!

296951 commented 2 years ago

@DRSDavidSoft No your fix is better. I am the lazy one!

d4k0 commented 2 years ago

@DRSDavidSoft Unfortunately, the issue persists:

2022-10-19_18-33-19

After the restart of Cmder:

2022-10-19_18-36-58

chrisant996 commented 2 years ago

@DRSDavidSoft @daxgames another option could be to use findstr instead of find. The init.bat file already uses findstr elsewhere.

chrisant996 commented 2 years ago

@dk40 The find program is no longer used in the latest init.bat file, so if you're still getting the same error then you don't have the fix yet.

Comment https://github.com/cmderdev/cmder/issues/2766#issuecomment-1283571660 suggests how to download the latest init.bat file for testing purposes.

d4k0 commented 2 years ago

@chrisant996 As you can see in my first screenshot I downloaded the latest init.bat file using the provided command. The download was successful as the date of the file changed. I then restarted Cmder and took the second screenshot.

DRSDavidSoft commented 2 years ago

Thanks

d4k0 commented 2 years ago

@DRSDavidSoft I accidentally started cmder.exe instead of cmd.exe by typing cmder in the address bar of Windows Explorer and noticed that the message somehow now doesn't appear anymore (that's the cmder installation where I downloaded the new init.bat file). Very strange.

I tried your other advice but somehow the init.bat file isn't updated as the date didn't change:

2022-10-19_20-48-21

2022-10-19_20-48-43

DRSDavidSoft commented 2 years ago

As I suspected, the init.bat was updated in the other directory.

Can you find the updated file (using the date) in vendor\init.bat, and copy manually to the correct folder, to see if it makes a difference?

If not, please run vendor\init.bat /d, so the debug mode is turned on, then copy the entire output and post it out as a .txt file so we can investigate.

Please remove any sensitive information first.

Thanks for putting the effort to debug the issue!

DRSDavidSoft commented 2 years ago

@DRSDavidSoft @daxgames another option could be to use findstr instead of find. The init.bat file already uses findstr elsewhere.

I can see the benefit of using findstr.exe to pipe the output of where or any command, instead of manually matching the string.

I vote to using findstr instead of find, firstly because the name won't conflict with Unix tools, and second for the sake of using consistent tools in cmder.

Should we revert back to it instead of my method?

d4k0 commented 2 years ago

I copied the new init.bat to a fresh installation of cmder and the message now isn't displayed anymore. Thanks for fixing this!

DRSDavidSoft commented 2 years ago

I copied the new init.bat to a fresh installation of cmder and the message now isn't displayed anymore. Thanks for fixing this!

Awesome, now we only need to decide which method to use. I vote keeping this one that works, but I'd also like the idea of using findstr.

daxgames commented 2 years ago

I am a for what works and is fastest.