我正在尝试在 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/