我正試圖使用powerhell版本的make,以便精簡一些需要多次運行的命令。
get-childitem -file | where {($_.extension -ne ".tex") -and ($_.extension -ne ".pdf") -and ($_.name -ne "Makefile")} |洗掉專案
因此,我在makefile中進行了如下設定:
clean:
get-childitem -file | where {($_.extension -ne " .tex") -and ($_.extension -ne ".pdf"/span>) -and ($_.name -ne "Makefile") } | 洗掉專案
當我運行make clean時,我得到一個錯誤:
get-childitem -file | where {(.extension -ne " . tex") -and (.extension -ne ".pdf") -and (.name -ne "Makefile") } remove-item
'get-childitem' is not recognized 為一個內部或外部命令。
可操作程式或批處理檔案。
撰寫。*** [Makefile:5: clean] 錯誤255。
為什么我會得到這個錯誤,我是否允許在Makefile中使用powerhell命令,如上圖所示?
uj5u.com熱心網友回復:
在Windows上,make使用cmd.exe作為其默認shell,而不是PowerShell。
你可以指導make使用PowerShell,在你的Makefiles頂部放置以下內容;改編自這個答案:
僅Windows,使用Windows PowerShell:
SHELL := powershell.exe
.SHELLFLAGS := -NoProfile -Command
# samples target that echoes information about the PowerShell edition and version.
# Note:
# *命令前面的'@'可以防止命令本身被呼出。
# * '$'對`make'本身有特殊含義,所以要傳遞一個逐字的'$'。
#傳遞給PowerShell,它必須被轉義為'$$' 。
.PHONY: demo
演示。
@$$PSVersionTable。
僅限Windows,使用PowerShell(Core)7 :
SHELL := pwsh.exe
.SHELLFLAGS := -NoProfile -Command
.PHONY: demo
演示。
@$$PSVersionTable。
跨平臺,在Windows上使用Windows PowerShell(以及在Unix類平臺上必須使用PowerShell(Core)7 ):
ifeq ($(OS),Windows_NT)
SHELL := powershell.exe
else
SHELL := pwsh
endif
.SHELLFLAGS := -NoProfile -Command
.PHONY: demo
演示。
@$$PSVersionTable[/span]。
跨平臺,在所有平臺上使用PowerShell(Core)7以上版本:
ifeq ($(OS),Windows_NT)
# Note: .exe在Windows上是*必須的;否則,
# make.exe 悄悄地回傳到 cmd.exe。
SHELL := pwsh.exe
else
SHELL := pwsh
endif
.SHELLFLAGS := -NoProfile -Command
.PHONY: demo
演示。
@$$PSVersionTable[/span]。
注意:
假設
pwsh/pwsh.exe,PowerShell(Core)的CLI,可以通過$env:PATH定位,官方安裝程式確保了這一點,但如果需要,你可以使用全路徑。- 注意:如前所述,在 Windows 上,您必須在檔案名/路徑中包含
.exe。如果make找不到可執行檔案,它就會悄悄地回傳到默認的 shell(Windows 上的cmd.exe,Unix-like 平臺的/bin/sh)。
- 注意:如前所述,在 Windows 上,您必須在檔案名/路徑中包含
內置的Windows PowerShell CLI,
powershell.exe,默認在$env:PATH。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/326687.html
標籤:
