0

我刚开始使用cmder,我注意到它启动时会发出一堆这样的错误消息:

The filename, directory name, or volume label syntax is incorrect.

'"C:\Program Files (x86)\cmder\config\profile.d\"Loading"' is not recognized as an internal or external command, operable program or batch file.

我挖掘了正在运行的各种启动文件,并将错误隔离为来自 init.bat 中的此块(最初设置程序时 cmder 安装程序创建的那个):

pushd "%CMDER_ROOT%\config\profile.d"
for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do (
  call :verbose-output Calling "%CMDER_ROOT%\config\profile.d\%%x"...
  call "%CMDER_ROOT%\config\profile.d\%%x"
)
popd

发生的事情是 %%x 被传递了在 profile.d 目录中找到的任何文件的名称(最初没有,所以我添加了一个空的 cmd 文件,它只是呼应了它的名称),还有“正在加载”这个词作为一个空字符串。我修改了当前版本的 init.bat 的来源以确定这一点,并且我尝试在“调用”部分周围放置一个条件,就像这样,它不像我期望的那样工作:

pushd "%CMDER_ROOT%\config\profile.d"
for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do (
  if "%%x" NEQ "" && "%%x" NEQ "Loading" (
      call :verbose-output Calling "%CMDER_ROOT%\config\profile.d\%%x"...
      echo "Calling %%x from init.bat..."
      call "%CMDER_ROOT%\config\profile.d\%%x"
  )
)
popd

我有点不知道该怎么做才能修复它(我写了很多 Unix/Linux shell 脚本,但几乎从不写任何 Windows 批处理程序)。此外,在 init.bat 的顶部是这样的:

:: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED

这是 init.bat 中的错误吗?这是我的设置导致这种情况的原因吗?我也在我的 PC 上运行 cygwin,这可能会造成这种情况吗?

有没有人对这里发生的事情以及我可以做些什么来解决它有任何建议?

附录:

“Magoo”提出了这样的改变:

if "%%x" NEQ "" IF "%%x" NEQ "加载中" ( ...

但这也不起作用;空字符串和“Loading”(实际上是“\”Loading”)仍在运行。这是编辑后的块:

pushd "%CMDER_ROOT%\config\profile.d"
for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do (
  echo "Calling *%%x* from init.bat..."
  if "%%x" NEQ "" IF "%%x" NEQ "Loading" (
      call :verbose-output Calling "%CMDER_ROOT%\config\profile.d\%%x"...
      call "%CMDER_ROOT%\config\profile.d\%%x"
  )
)
popd

这是现在输出的内容:

Calling ** from init.bat...
The filename, directory name, or volume label syntax is incorrect.
Calling *"Loading* from init.bat...
'"C:\Program Files (x86)\cmder\config\profile.d\"Loading"' is not recognized as an internal or external command, operable program or batch file.

附录 2:

我想我已经想出了一种可能的解决方案,一种临时的解决方案,它应该可以在 init.bat 被覆盖之前工作。如果我将有问题的块更改为以下内容,它似乎可以正常工作:

pushd "%CMDER_ROOT%\config\profile.d"
for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do (
  IF DEFINED x IF EXIST "%%x" (
      call "%%x"
  )
)
popd

这仍然不能解释为什么首先会生成两个有问题的字符串(“”和“加载”),但我会解决这个问题......

4

1 回答 1

1
if "%%x" NEQ "" && "%%x" NEQ "Loading" (

不会像你期望的那样工作。if很简单`if value op value dothis'

你需要

if "%%x" NEQ "" IF "%%x" NEQ "Loading" (

也就是说,第二ifdothis第一,创造和and条件。

不过,我建议您echo %%x事先 - 查看正在处理的实际文件名。

至于它被覆盖 - 好吧,如果你调整它,作者将在安装更新时覆盖它 - 所以保存一个副本并重新应用你的更改。

于 2017-04-10T14:38:35.397 回答