简体   繁体   English

FOR命令不会在.cmd文件中运行,但会在命令提示符下运行

[英]FOR command won't run in .cmd file, but runs at command prompt

When I try to run file.cmd containing the following: 当我尝试运行包含以下内容的file.cmd

for /l %m in (1,1,1) do @for /f "tokens=1,2* delims=:" %a in ('findstr /n /r "^" csv\data.csv ^| findstr /r "^%m:"') do @echo %b >csv\header.csv

I get this error: 我收到此错误:

" m:")'. Unexpected at this time

But when I run that same command at a command prompt (no .cmd file), it works. 但是,当我在命令提示符下运行同一命令(没有.cmd文件)时,它可以工作。

You realize there is a much much much simpler way to get the first line of a file into a variable. 您意识到将文件的第一行放入变量的方法要简单得多。

set /p header=<data.csv
echo %header%>header.csv

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM