command-line - Windows 批处理错误 : "' ping' is not recognized as an internal or external command operable program or batch file."

标签 command-line batch-file cmd command-line-arguments

我正在尝试在 Windows 中运行此命令:

ping -n 5 127.0.0.1 > nul

我收到错误:
'ping' is not recognized as an internal or external command operable 
program or batch fie. 

为什么windows找不到ping? 这是我的脚本不起作用的地方:
@ECHO OFF

::set path
SET path=M:\\5.bmp

:findfile
IF EXIST %path% (
    ECHO File found
) ELSE (
    ECHO File not found
    ping -n 5 127.0.0.1 > nul
    goto findfile
)

最佳答案

您已覆盖 PATH环境变量,因此命令处理器无法再找到 ping可执行。

修复既好又简单 - 只需使用不同的变量名称!

:: set path
SET MyPath=M:\\5.bmp

:findfile
IF EXIST %MyPath% (

请注意,如果您真的想设置 path环境变量,你应该像这样附加到它:
REM Set temporarily for this session
SET PATH=%PATH%;C:\Some\Folder

REM Set permanently (but note - this change will not be made to this session)
SETX PATH=%PATH%;C:\Some\Folder

关于command-line - Windows 批处理错误 : "' ping' is not recognized as an internal or external command operable program or batch file.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15088857/

相关文章:

linux - 将一个命令的输出重定向到多个命令

mysql - 如何将 bzip 的输出通过管道传输到 mysql,以将数据直接从 bzip 压缩文件恢复到数据库中

windows - 用于重命名多个文件夹的 .bat 文件

Windows CMD - 运行程序并指定图像名称

powershell - 使用批处理/powershell 脚本设置自定义行分隔符

grails - 在CMD上运行Grails 3应用程序时出错

android - 如何使用 Google App 签名为 Sms Retriever 生成 11 个字符的哈希 key

php - 在 PHP 中解析 Linux 命令 'who' 的输出

windows - 删除空行

html - Windows 批处理文件脚本 - 保持 html 格式