简体   繁体   English

使用 makefile 在 Windows 上运行批处理文件时找不到命令 10

[英]command not found when using makefile to run batch file on Windows 10

When I try to run a makefile (type "make test" in terminal) which runs a batch file I get the equivalent error:当我尝试运行运行批处理文件的 makefile(在终端中键入“make test”)时,我得到了等效的错误:

cd directory_path && test.bat
/bin/sh: test.bat: command not found
make: *** [makefile:58: test] Error 127

The makefile is: makefile 是:

.PHONY: test
test:
    cd directory_path && test.bat
    python path/test.py

(I changed names of the batch file, the directory path, etc. to try and make things more generic) (我更改了批处理文件的名称、目录路径等,以尝试使事情更通用)

I can manually type "cd directory_path" and then "test.bat" and those both work.我可以手动输入“cd directory_path”,然后输入“test.bat”,它们都可以工作。 This makefile works on other systems.这个 makefile 适用于其他系统。 It only doesn't work on mine.它只对我不起作用。 I think it is an issue with how I installed Cygwin and how I run "make.exe".我认为这是我如何安装 Cygwin 以及如何运行“make.exe”的问题。

I can use make to compile C code, but I also get an error trying to use make to run python scripts.我可以使用 make 来编译 C 代码,但是我在尝试使用 make 运行 python 脚本时也会出错。 The makefile from before also has a command for python path/test.py.之前的 makefile 也有 python path/test.py 的命令。 This also isn't working on my system.这在我的系统上也不起作用。 If I delete the batch file line, but keep the python command it throws the error:如果我删除批处理文件行,但保留 python 命令,它会抛出错误:

python path/test.py
make: python: No such file or directory
make: *** [makefile:59: test] Error 127.

I don't understand why it throws the error of no such file or directory since the path leads to the file, and if i put the python script in the same working directory as the makefile then it still can't find it.我不明白为什么它会抛出没有这样的文件或目录的错误,因为路径指向文件,如果我将 python 脚本放在与 makefile 相同的工作目录中,那么它仍然找不到它。

Any ideas/solutions on these problems?关于这些问题的任何想法/解决方案? Thank you!谢谢!

EDIT:编辑:

Doug Henderson: I started a cmd prompt at the place with the make file and entered all of these commands in Doug Henderson:我在 make 文件所在的位置启动了 cmd 提示符,并在

uname -a
CYGWIN_NT-10.0 james-mobl2 3.1.6(0.340/5/3) 2020-07-09 08:20 x86_64 Cygwin

which make
/usr/bin/make

make -v
GNU Make 4.3
Built for x86_64-pc-cygwin
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

which python
which: no python in
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)

(I cleaned up the output a little to make it more legible). (我稍微清理了 output 以使其更清晰)。 This and which test.bat are the only commands that failed. This 和 which test.bat 是唯一失败的命令。

python -V
Python 3.8.5

The change directory changed correctly更改目录正确更改

which test.bat
which: no test.bat in 
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)

I added cmd /c test.bat to the makefile and it worked, but I've also had the batch file run on different systems without that addition.我将cmd /c test.bat添加到 makefile 并且它起作用了,但我也让批处理文件在没有添加的情况下在不同的系统上运行。 I also have a lot batch files in the actual makefile so this solution works but isn't ideal.我在实际 makefile 中也有很多批处理文件,因此此解决方案有效但并不理想。 It also didn't fix the python script not running.它还没有修复 python 脚本未运行的问题。

I didn't initially have cmd.exe in my path, but I added it before entering those commands.我的路径中最初没有 cmd.exe,但我在输入这些命令之前添加了它。

I'm not sure what you mean by starting my PATH in bash with /usr/bin;/bin;THE_REST我不确定您在 bash 中使用/usr/bin;/bin;THE_REST启动我的 PATH 是什么意思

MadScientist: I was manually entering it into a Windows Terminal. MadScientist:我手动将其输入到 Windows 终端。 Is it possible to have Cygwin invoke a Windows command.com shell?是否可以让 Cygwin 调用 Windows 命令。com shell?

What I did was go to directory that contained the makefile. Open a windows terminal by typing 'cmd' in the address bar.我所做的是 go 到包含 makefile 的目录。通过在地址栏中键入“cmd”打开 windows 终端。 I would then type 'make test'.然后我会输入“进行测试”。 That obviously led to the issues.这显然导致了问题。 I then went through and manually entered the commands I thought the makefile was supposed to invoke.然后我通过并手动输入了我认为 makefile 应该调用的命令。 So I entered 'cd directory_path && test.bat'.所以我输入了“cd directory_path && test.bat”。 This ran.这跑了

Matzeri: I don't really know.马策里:我真的不知道。 I'm completely new to POSIX, etc. I'm guessing I'm using Windows style, and judging from other responses, I'm trying to use Cygwin to do a non-POSIX style.我对 POSIX 等完全陌生。我猜我正在使用 Windows 样式,并且从其他响应来看,我正在尝试使用 Cygwin 来执行非 POSIX 样式。

Thank you, everyone for responses!谢谢大家的回复!

  1. Make sure cygwin is installed with basic packages --> Some basic packages not installed with cygwin try below link to install some basic package, uninstall the cygwin and install it again with following basic package: https://wiki.usask.ca/display/MESH/Running+Python+from+the+Cygwin+Terminal#RunningPythonfromtheCygwinTerminal-Cygwin确保 cygwin 与基本包一起安装 --> 一些没有与 cygwin 一起安装的基本包尝试下面的链接来安装一些基本的 package,卸载 cygwin 并使用以下基本的 package 重新安装: https://wiki.usask.ca/display /MESH/运行+Python+from+the+Cygwin+Terminal#RunningPythonfromtheCygwinTerminal-Cygwin

  2. make sure cygwin's bin folder is added to your environment variable (eg, C:\cygwin64\bin)确保将 cygwin 的 bin 文件夹添加到您的环境变量中(例如,C:\cygwin64\bin)

If cmd /c test.bat works then .如果cmd /c test.bat有效,那么. is probably not in your PATH.可能不在您的路径中。 Always do ./test.bat when you want to run something in the current directory.当你想在当前目录中运行某些东西时,总是执行./test.bat Never count on the PATH unless you have set it yourself.除非您自己设置,否则永远不要指望 PATH。 Also make sure the file is executable.还要确保该文件是可执行的。 chmod +x test.bat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows 10上的Makefile - 找不到文件 - Makefile on Windows 10 - file not found 在Windows批处理文件中运行Python命令 - Run Python command in a Windows batch file 无法使用Windows命令行和批处理文件运行脚本 - Can't get script to run using windows command line with batch file Heroku 命令在 Windows 中找不到 10 - Heroku command not found in Windows 10 flask 命令未在 windows 中找到 10 - flask command not found in windows 10 使用 subprocess.run 自动化命令行应用程序(Windows 10) - using subprocess.run to automate a command line application (windows 10) 在 Windows 10 中使用 pyinstaller 创建的 exe 文件在 Windows 8 中无法运行 - exe file created using pyinstaller in windows 10 does not run in windows 8 sqlite3:在Windows 10上找不到Python 3命令 - sqlite3: command not found Python 3 on Windows 10 &#39;jupyter&#39; 在 Windows 10 中未被识别为内部或外部命令、可运行的程序或批处理文件 - 'jupyter' is not recognized as an internal or external command, operable program or batch file in Windows 10 Python 和 Windows 10:“telnet”不是内部或外部命令、可运行的程序或批处理文件 - Python and Windows 10: 'telnet' is not recognized as an internal or external command, operable program or batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM