【发布时间】:2020-06-19 10:01:36
【问题描述】:
我编写了一个小批处理脚本来将我的 html 文件解析为 cpp-Header 文件,以便我可以将其编译为 ESP8266 (PROGMEM)。脚本很简单:
@echo off
set /P filename=Enter File name (w/o .html extension):
if exist "..\website\%filename%.html" (
echo|set /p dummyvar=%filename%>beforetemp.txt
type before.txt beforetemp.txt before2.txt "..\website\%filename%.html" after.txt > "..\server\%filename%html.h"
) else (
echo FILE at website\%filename%.html DOES NOT EXISTS!
pause
)
exit 0
在我添加可以输入要复制的文件名称的部分之前,一切正常。
所有完成的文件应该如下所示:
#include <arduino.h>
const char indexhtml[] PROGMEM = R"====(
<html>
...
</html>
)====";
但是当我运行脚本时,它会在 beforetemp.txt 的末尾插入一个空格字符,因此会在我的 indexhtml.h 文件中搞砸变量名。 before.txt beforetemp.txt before2.txt 的东西变成了
#include <arduino.h>
const char index html[] PROGMEM = R"====(
而不是
#include <arduino.h>
const char indexhtml[] PROGMEM = R"====(
问题是:如何将 before.txt 和 before2.txt 之间的 %filename% 的内容打印到我的新文件中?
这里是使用的文件:
before.txt
#include <arduino.h>
const char
before2.txt
html[] PROGMEM = R"====(
之后.txt
)====";
【问题讨论】:
-
为了明确一点:问题出在脚本的第 4 行,type 命令本身完美无缺,因为空格字符已经存在于 beforetemp.txt 文本文件中。
-
你为什么使用
type而不是copy从其他几个文件创建一个文件?打开command prompt,运行copy /?并阅读输出帮助。可以运行copy选项/B和几个输入文件,它们之间有+和一个输出文件名,以将输入文件的内容按指定顺序复制到指定的输出文件中。type在使用多个文件名运行它时还会输出文件名,我怀疑这是否会产生有效的头文件。 -
用
< nul set /P ="%filename%"替换echo|set /P dummyvar=%filename%… -
@aschipfl 完全按预期工作,非常感谢 :)
标签: batch-file cmd arduino windows-console