Can't figure out how to read file from nmake

陌路散爱 提交于 2019-11-28 09:41:49

问题


I am doing something like this:

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

However the filecontent variable does not seem to hold the contents of the file somefile.txt.


回答1:


Simply ensure somefile.txt is in acceptable nmake syntax, and then !include it. Thus:

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



回答2:


It is possible to read a file that is not a valid nmake file using !INCLUDE. For examle if we have a version file version that contains a single line of text we can do that:

//version file
1.2.4

//makefile
VERSION= \
!INCLUDE <version>

It is not working if the file contains more than one line.




回答3:


You could try something like this:

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

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

#--- END ---

I think a cmd/bat file run within nmake.exe cannot affect the environment of nmake. So you must use the password that you grabbed from the secret.txt within the temporary cmd file.



来源:https://stackoverflow.com/questions/3745261/cant-figure-out-how-to-read-file-from-nmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!