执行make copy命令报错(e=2)求助:系统找不到指定文件
问题分析与解决
问题现象
执行copy forbidden.html build\testing\forbidden.html命令时出现报错:
process_begin: CreateProcess(NULL, copy forbidden.html build\testing\forbidden.html, ...) failed. make (e=2): The system cannot find the file specified. make: *** [Makefile:16: copy] Error 2
系统Path包含git-local\bin时,make copy执行失败;移除该路径后命令正常运行。添加$(info $(SHELL))到Makefile,Path含Git路径时输出git_local\bin\sh.exe,移除后仅显示sh.exe。给含空格路径加引号无法解决问题。
根因分析
- Git自带的
sh.exe是类Unix风格的shell,它不支持Windows原生的copy命令,类Unix环境中复制文件的标准命令是cp。 - 当
git-local\bin在系统Path中时,make会优先调用Git的sh.exe作为执行shell,此时执行copy命令,该shell无法识别这个Windows专属命令,因此抛出“找不到文件”的错误(实际是找不到copy命令本身)。 - 移除Git路径后,make使用的是系统默认的shell(通常是Windows cmd.exe或兼容Windows命令的sh环境),这类shell能识别
copy命令,因此执行正常。
解决办法
- 修改复制命令为跨平台格式:将Makefile中的
copy替换为cp,Git的sh.exe支持cp命令,同时多数Windows下的开发环境也自带cp的实现,这样无论使用哪种shell都能正常执行。 - 强制指定make使用Windows cmd.exe:在Makefile的开头添加一行:
这样make会直接用Windows的命令行解释器执行SHELL := cmd.execopy命令,不受Git shell的影响。 - 调整Path顺序:将
git-local\bin移到系统Path的末尾,让make优先使用系统默认的shell,而非Git的sh.exe。
内容的提问来源于stack exchange,提问作者Suto Oliver
相关产品推荐
相关产品推荐

