代码之家  ›  专栏  ›  技术社区  ›  Youssif Saeed

生成文件窗口:…更改目录时不被识别为内部或外部命令

  •  0
  • Youssif Saeed  · 技术社区  · 7 年前

    当我试图从Windows中的makefile中更改目录时,我看到了一个奇怪的问题。我的伪代码如下:

    all:
        cd ../ProjectDir && ../AutoExc InputFile.h
    

    其中autoexc是我在父目录中拥有的可执行文件。当我从命令行运行“make”时,我看到以下输出:

    cd ../ProjectDir && ../AutoExc InputFile.h
    '..' is not recognized as an internal or external command.
    

    奇怪的是,在Linux中运行这个精确的makefile是可行的。我还尝试从Windows中的命令行运行上述命令,但它运行正常,因此“cd”没有问题。

    知道为什么会发生这种情况吗?我该怎么做才能让它工作?如果make版本有问题,是否还有其他更可靠的机制来更改目录并在Windows上运行可执行文件?

    我在Windows7上使用Make3.81(最新版本),在Linux4.15.0-20-generic 21 Ubuntu上使用Make4.1。我安装了“cd”作为“git for windows”的一部分,git版本是2.16.1.windows.4。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Stefan Becker    7 年前

    您的命令包含shell字符,并传递给 cmd.exe :

    >cd ../Public &&  ../test
    '..' is not recognized as an internal or external command,
    operable program or batch file.
    
    >cd ../Public &&  ..\test
    '..\test' is not recognized as an internal or external command,
    operable program or batch file.
    

    命令提示符 解释 ../test 作为命令 .. 有选择权 /test .

    我想有一种解决方案可以将宏应用于具有路径的命令名,例如( 笔记 :未测试,刚从我的头上键入):

    if (...I'm running under Windows...)
      convert_path = $(subst /,\\,$(1))
    else
      convert_path = $(1)
    endif
    
    all:
        cd ../ProjectDir && $(call convert_path,../AutoExc) InputFile.h
    

    或者,如果可能,使用评论中的建议 SHELL := /bin/sh ,或者在您的Windows环境中指向与Unix兼容的shell的正确路径。”Git for Windows“是基于Mingw的,所以您应该 bash 可用。