批处理文件-系统在Powershell中找不到路径/找不到命令错误



我安装了一个Elasticsearch,几个月来一直运行良好,但根据Powershell的说法,它莫名其妙地失踪了。我唯一能想到的最近发生了变化的是我更新了Java。

当我尝试使用完整路径运行它时,我会得到以下错误:

PS C:> C:elasticsearchbinelasticsearch.bat
The system cannot find the path specified.

路径存在,没有拼写错误,你可以在这里看到:

PS C:elasticsearchbin> dir
    Directory: C:elasticsearchbin
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         8/7/2016  10:13 PM           5551 elasticsearch
-a----         8/7/2016  10:13 PM         104448 elasticsearch-service-mgr.exe
-a----         8/7/2016  10:13 PM         103936 elasticsearch-service-x64.exe
-a----         8/7/2016  10:13 PM          80896 elasticsearch-service-x86.exe
-a----         8/7/2016  10:13 PM            909 elasticsearch.bat
-a----         8/7/2016  10:13 PM           3307 elasticsearch.in.bat
-a----         8/7/2016  10:13 PM           2814 elasticsearch.in.sh
-a----         8/7/2016  10:13 PM           2992 plugin
-a----         8/7/2016  10:13 PM           1303 plugin.bat
-a----         8/7/2016  10:13 PM           6501 service.bat

当我尝试在目录中运行它时,我会得到以下消息:

PS C:elasticsearchbin> elasticsearch.bat
elasticsearch.bat : The term 'elasticsearch.bat' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ elasticsearch.bat
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (elasticsearch.bat:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Suggestion [3,General]: The command elasticsearch.bat was not found, but does exist in the current location. Windows Pow
erShell does not load commands from the current location by default. If you trust this command, instead type: ".elastic
search.bat". See "get-help about_Command_Precedence" for more details.

我对处理Powershell错误没有很强的了解,所以我只尝试了几件事:

  1. 重新安装Elasticsearch
  2. 将包含elasticsearch.bat的目录添加到路径
  3. 使用命令运行elasticsearch.bat/弹性搜索.bat

这些都没有改变任何事情。

以下是elasticsearch.bat:的内容

@echo off
SETLOCAL enabledelayedexpansion
TITLE Elasticsearch 2.3.5
SET params='%*'
:loop
FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO (
    SET current=%%A
    SET params='%%B'
    SET silent=N
    IF "!current!" == "-s" (
        SET silent=Y
    )
    IF "!current!" == "--silent" (
        SET silent=Y
    )   
    IF "!silent!" == "Y" (
        SET nopauseonerror=Y
    ) ELSE (
        IF "x!newparams!" NEQ "x" (
            SET newparams=!newparams! !current!
        ) ELSE (
            SET newparams=!current!
        )
    )
    IF "x!params!" NEQ "x" (
        GOTO loop
    )
)
SET HOSTNAME=%COMPUTERNAME%
CALL "%~dp0elasticsearch.in.bat"
IF ERRORLEVEL 1 (
    IF NOT DEFINED nopauseonerror (
        PAUSE
    )
    EXIT /B %ERRORLEVEL%
)
"%JAVA_HOME%binjava" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" start !newparams!
ENDLOCAL
PS C:> C:elasticsearchbinelasticsearch.bat
The system cannot find the path specified.

您确定这不是批处理文件的输出吗?换句话说,批处理文件中的某些内容找不到指定的路径(可能是java.exe(。如果PowerShell找不到该文件,您将收到类似第二次尝试的错误消息。

谈到你的第二次尝试:

PS C:elasticsearchbin> elasticsearch.bat

正如错误消息所述,这对当前文件夹中的文件不起作用。您需要明确指定当前文件夹:

PS C:elasticsearchbin> .elasticsearch.bat

最新更新