2010-09-19 107 views
0

我做這樣的讀文件:無法弄清楚如何從NMAKE


all: 
@SET /p filecontent= < somefile.txt 
@echo %filecontent% 

然而filecontent變量似乎並沒有保存文件somefile.txt的內容

+0

你希望對內容做什麼?有可能有更好的方法來做到這一點。 – crazyscot 2010-09-19 10:51:14

+0

somefile.txt是一個包含密碼的單行文件,我不想在每個makefile中進行硬編碼 – 2010-09-19 10:56:58

回答

1

只需確保somefile.txt處於可接受的nmake語法,然後!include它。因此:

c:>type somefile.txt 
PASSWORD=secret 
c:>type makefile 
!INCLUDE somefile.txt 
!MESSAGE Password is [$(PASSWORD)] 
c:>nmake -nologo 
Password is [secret] 
0

你可以試試像這樣:

# ---- vitaly.mak ---- 

target1: 
# create and invoke a temporary cmd file 
@<<mygetpassword.cmd 
@echo off 
setlocal 
@SET /p filecontent= < secret.txt 
@echo %filecontent% 
endlocal 
<< 

#--- END --- 

我認爲a cmd/bat file run within nmake.exe cannot affect the environment of nmake。因此,您必須使用使用您從臨時cmd文件內的secret.txt中抓取的密碼。

-1

它可以讀取一個文件,是不使用!INCLUDE有效NMAKE文件。對於examle如果我們有一個包含單個文本行,我們可以做一個版本的文件version

//version file 
1.2.4 

//makefile 
VERSION= \ 
!INCLUDE <version> 

如果文件中包含一個以上的線這是行不通的。